Overview
| Artifact ID: | e10b763a5de8f0a3b3575b4c4e92f4a3219638ec7e12d15b90817fdbf3991c33 |
|---|---|
| Ticket: | 62144fdc02ef37b0fcbdbbcd05ffb8375446f536
"scan NaN %f" returns a list with an empty element |
| User & Date: | kuehro on 2026-07-24 07:45:26 |
Changes
- icomment:
There are two ways to fix the deficient math of our beloved Tcl: 1) Build your own Tcl with line 26 of generic/tclInt.h changed to #define ACCEPT_NAN 2) Download mymath.tcl from https://gist.github.com/yyamasak/b1ce55c40631b1c1ea6e8200dba3f7e0 and change line 109 from if {$res eq "domain error: argument not in valid range"} { to if {$res eq "domain error: argument not in valid range" || \ [string first "non-numeric" $res] > 0} { Now you can use myexpr instead of expr, for example with 8.6.18 and 9.1b1 we get: % set $n -nan -nan % puts [myexpr {2.0+$n}] NaN % puts [myexpr {1.0/0.0}] Inf % puts [myexpr {0.0/0.0}] NaN Searching for nan at https://core.tcl-lang.org/tips/doc/trunk/index.md shows several TIPs related to proper math handling (520,521, 731, ...). Method 1) still has inconsequent handling of the sign, i.e. -NaN vs NaN and method 2) can be used without recompiling but needs myexpr instead of expr. Working in a scientific workplace I had to abandon the use of Tcl for this reason but for many use cases method 1) or 2) might be viable. Good luck, Kai-Uwe - login: "kuehro"
- mimetype: "text/plain"