Overview
| Artifact ID: | 31fcc7f7d38d64487e639fa8bbb4f0a52667091e |
|---|---|
| Ticket: | 3105247fffffffffffffffffffffffffffffffff
-NaN? |
| User & Date: | nijtmans on 2010-11-10 16:46:15 |
Changes
- icomment:
OK, I'll explain why I think that Christoph is right. The relevant TIP here is TIP #249: Unification of Tcl's Parsing of Numbers The implentation came from the kennykb-numerics-branch, which came with Tcl 8.5: 2005-05-10 Kevin Kenny <[email protected]> Merged all changes on kennykb-numerics-branch back into the HEAD. TIP's 132 and 232 are now Final. This TIP #249 states: 8. The constants, "Inf", and "Infinity" (perhaps with a leading signum) are interpreted as infinities. Infinity is represented as tclDoubleType. 9. The constant "NaN" is the IEEE "Not a Number" value. It is specifically permitted in the parser so that binary format q NaN and similar calls can produce NaN on an external medium. The presence of NaN in expressions, or in Tcl_GetDoubleFromObj, signals an error. NaN is represented as tclDoubleType. 10. IEEE floating point does not have a single unique NaN value, so a NaN may be augmented by a parenthesized string of hexadecimal digits, which will be stored in its least significant bits. It shall not be possible to construct signalling NaN by this route; only quiet NaN will be supported. NaN is represented as tclDoubleType. Nothing wrong here, except that nowhere is mentioned that NaN's may be negative as well as Inf. The only place it can be derived that NaN's may be negative is the state diagram, but I would argue that in this respect, the state diagram does not match the text. How does libc it? Some C-code: double d; memcpy(&d, "\000\000\000\000\000\000\370\177", 8); printf("%g\n", d); memcpy(&d, "\000\000\000\000\000\000\370\377", 8); printf("%g\n", d); memcpy(&d, "\001\000\000\000\000\000\370\177", 8); printf("%g\n", d); memcpy(&d, "\001\000\000\000\000\000\370\377", 8); printf("%g\n", d); On Windows XP (mingw), this prints: 1.#QNAN -1.#QNAN 1.#QNAN -1.#QNAN On Linux (Ubuntu 10.4, AMD64) nan -nan nan -nan In Java Double d = Double.longBitsToDouble(0x7ff8000000000000L); System.out.println(d); d = Double.longBitsToDouble(0xfff8000000000000L); System.out.println(d); d = Double.longBitsToDouble(0x7ff8000000000001L); System.out.println(d); d = Double.longBitsToDouble(0xfff8000000000001L); System.out.println(d); This prints NaN NaN NaN NaN So, what should we follow? The C way, which is non-portable (as in Tcl 8.4). Or the Java way, which doesn't have a -NaN? Currently we use a mixture, which is not well described in TIP #249 More opinions?
- login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"