Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ef6c5edfa10130d6c83c7d417222b1b94a948c4c218238320dfe6e879979adef
Ticket: 42d14c495a096159841d2601a16850273713b31b
Parsing long floating point strings
User & Date: oehhar on 2025-05-03 13:19:03
Changes

  1. icomment:
    Christian Werner explained to me, that this issue specially happens, if an external lib delivers a double as string representation.
    This bug was introduced with libtommath 20 years ago.
    
    The problem is, that a double scan of the string "1.[string repeat 1 191]e-321" results in a very large number:
    
    <verbatim>
    scan
    "1.11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e-321" %g
    8.2870452568891191e+036
    </verbatim>
    
    While one "1" less results in an acceptable number close to the value:
    
    <verbatim>
    scan "1.[string repeat 1 190]e-321" %g
    1.11e-321
    </verbatim>
    
    More ones in the mantissa let the scanned value grow. With 703 1's, Inf is reached.
    
    I have put those two lines in tests by this commit: [4351b324].
    I am not sure, if this is very stable, but I get the same results on Windows with 8.6 32bit and main 64bit.
    
    I suppose, it would be better to have a test case with a range check...
    
    I hope with this test, we may merge the branch.
    
    Thanks for all,
    Harald
    
  2. login: "oehhar"
  3. mimetype: "text/x-fossil-wiki"
  4. username: "oehhar"