Overview
| Artifact ID: | 19323fcb5bedf6406bf7634baadf65741ad26fa24f53c543afcc82b844af746d |
|---|---|
| Ticket: | 42d14c495a096159841d2601a16850273713b31b
Parsing long floating point strings |
| User & Date: | sebres on 2023-10-13 15:16:58 |
Changes
- icomment:
Tcl doesn't use `long double` for internal conversions before it gets stored to `double`... Historically instead it uses mp-math, e. g. wide+bignum with significand and int for significant digits and calculate `double` with something like `AccumulateDecimalDigit` and `MakeHighPrecisionDouble` or `MakeLowPrecisionDouble` (if no significand bignum is used), which may overflow differently to `long double` conversion which can be used internally by C-libs in `sscanf` for `%lg`. However myself would prefer that nothing overflows here at all in TclParseNumber by such FP conversion (at least by negative exponent), neither to `8.28e+36` nor and even less to `Inf`. Rather I'd expect that the number would near to `1.11e-321` in that case and to `0.0` in cases below smallest positive double close to zero (`2.0**-1074` so ca. `5e-324` in IEEE 754's double), no matter how long the mantissa becomes.<br/> In the way like this diff illustrates: ```diff % for {set i 189} {$i < 193} {incr i} { puts [expr 0.[string repeat 1 $i]e-320] } 1.11e-321 1.11e-321 1.11e-321 - 8.287045256889119e+36 + 1.11e-321 % for {set i 189} {$i < 193} {incr i} { puts [expr 1.[string repeat 1 $i]e-321] } 1.11e-321 1.11e-321 - 8.287045256889119e+36 - 8.287045256889119e+36 + 1.11e-321 + 1.11e-321 % for {set i 189} {$i < 193} {incr i} { puts [expr 10.[string repeat 1 $i]e-322] } 1.013e-321 - 7.541211183769098e+36 - 7.541211183769098e+36 - 7.541211183769098e+36 + 1.11e-321 + 1.11e-321 + 1.11e-321 ``` Also for real overflow this could be more "tclish" since Tcl's numeric values are more dynamic and must not necessarily overflow by implicit conversions, even if it could overflow in C. This can be achieved by shift of significant bits (move float-point) and/or increase of exponent and/or simply trim of right (needless) part of mantissa by reaching of some threshold. - login: "sebres"
- mimetype: "text/x-markdown"