<i>Parsing long floating point strings</i> status still Open with 3 other changes
by
.
D 2023-10-13T15:16:58.999
J icomment Tcl\sdoesn't\suse\s`long\sdouble`\sfor\sinternal\sconversions\sbefore\sit\sgets\sstored\sto\s`double`...\sHistorically\sinstead\sit\suses\smp-math,\se.\sg.\swide+bignum\swith\ssignificand\sand\sint\sfor\ssignificant\sdigits\sand\scalculate\s`double`\swith\ssomething\slike\s`AccumulateDecimalDigit`\sand\s`MakeHighPrecisionDouble`\sor\s`MakeLowPrecisionDouble`\s(if\sno\ssignificand\sbignum\sis\sused),\swhich\smay\soverflow\sdifferently\sto\s`long\sdouble`\sconversion\swhich\scan\sbe\sused\sinternally\sby\sC-libs\sin\s`sscanf`\sfor\s`%lg`.\r\n\r\nHowever\smyself\swould\sprefer\sthat\snothing\soverflows\shere\sat\sall\sin\sTclParseNumber\sby\ssuch\sFP\sconversion\s(at\sleast\sby\snegative\sexponent),\sneither\sto\s`8.28e+36`\snor\sand\seven\sless\sto\s`Inf`.\sRather\sI'd\sexpect\sthat\sthe\snumber\swould\snear\sto\s`1.11e-321`\sin\sthat\scase\sand\sto\s`0.0`\sin\scases\sbelow\ssmallest\spositive\sdouble\sclose\sto\szero\s(`2.0**-1074`\sso\sca.\s`5e-324`\sin\sIEEE\s754's\sdouble),\sno\smatter\show\slong\sthe\smantissa\sbecomes.<br/>\r\n\r\nIn\sthe\sway\slike\sthis\sdiff\sillustrates:\r\n\r\n```diff\r\n\s\s%\sfor\s{set\si\s189}\s{$i\s<\s193}\s{incr\si}\s{\sputs\s[expr\s0.[string\srepeat\s1\s$i]e-320]\s}\r\n\s\s1.11e-321\r\n\s\s1.11e-321\r\n\s\s1.11e-321\r\n-\s8.287045256889119e+36\r\n+\s1.11e-321\r\n\r\n\s\s%\sfor\s{set\si\s189}\s{$i\s<\s193}\s{incr\si}\s{\sputs\s[expr\s1.[string\srepeat\s1\s$i]e-321]\s}\r\n\s\s1.11e-321\r\n\s\s1.11e-321\r\n-\s8.287045256889119e+36\r\n-\s8.287045256889119e+36\r\n+\s1.11e-321\r\n+\s1.11e-321\r\n\r\n\s\s%\sfor\s{set\si\s189}\s{$i\s<\s193}\s{incr\si}\s{\sputs\s[expr\s10.[string\srepeat\s1\s$i]e-322]\s}\r\n\s\s1.013e-321\r\n-\s7.541211183769098e+36\r\n-\s7.541211183769098e+36\r\n-\s7.541211183769098e+36\r\n+\s1.11e-321\r\n+\s1.11e-321\r\n+\s1.11e-321\r\n```\r\n\r\nAlso\sfor\sreal\soverflow\sthis\scould\sbe\smore\s"tclish"\ssince\sTcl's\snumeric\svalues\sare\smore\sdynamic\sand\smust\snot\snecessarily\soverflow\sby\simplicit\sconversions,\seven\sif\sit\scould\soverflow\sin\sC.\r\n\r\nThis\scan\sbe\sachieved\sby\sshift\sof\ssignificant\sbits\s(move\sfloat-point)\sand/or\sincrease\sof\sexponent\sand/or\ssimply\strim\sof\sright\s(needless)\spart\sof\smantissa\sby\sreaching\sof\ssome\sthreshold.
J login sebres
J mimetype text/x-markdown
K 42d14c495a096159841d2601a16850273713b31b
U sebres
Z 947aae5fc98428dfc2c917654d5c5281