Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Enhance TIP #514 rationale |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
68cc144274c94f3b338de4c0db4880d9 |
User & Date: | jan.nijtmans 2018-08-23 13:23:38.971 |
Context
2018-08-23
| ||
13:27 | missing minus sign (quite important ....) check-in: 5441fa571a user: jan.nijtmans tags: trunk | |
13:23 | Enhance TIP #514 rationale check-in: 68cc144274 user: jan.nijtmans tags: trunk | |
2018-08-21
| ||
07:25 | Re-generate index check-in: 15a89a0458 user: jan.nijtmans tags: trunk | |
Changes
Changes to tip/514.md.
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 | # Abstract This TIP proposes to resolve the platform differences between int/wide math functions and commands like "sting is integer"/"string is wide". At the script level it should not be relevant whether the platform is 32-bit or 64-bit any more. Originally, the int() math function was meant to be provide compatibility when introducing big integers using the libtommath library. Code depending on the modulo behavior of all expressions could use the int() function to make the behavior the same as in Tcl 8.4 again. # Rationale | > > | > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | < | < | | | | > > | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | # Abstract This TIP proposes to resolve the platform differences between int/wide math functions and commands like "sting is integer"/"string is wide". At the script level it should not be relevant whether the platform is 32-bit or 64-bit any more. Originally, the int() math function was meant to be provide compatibility when introducing big integers using the libtommath library. Code depending on the modulo behavior of all expressions could use the int() function to make the behavior the same as in Tcl 8.4 again. In practice, the int() math function is rarely used. # Rationale Some examples: <pre> % string is int -4294967296 0 % string is int -4294967295 1 % string is int 4294967295 1 % string is int 4294967296 0 </pre> So, valid integers appear to range from -(2^32-1) to +2^32-1. Most people learn in school that 32-bit integers range from -2^31 to 2^31-1. Are Tcl's integers 33-bit, but then excluding -4294967296? <pre> % string is wide -18446744073709551616 0 % string is wide -18446744073709551615 1 % string is wide 18446744073709551615 1 % string is wide 18446744073709551616 0 </pre> So, valid wide integers appear to range from -2^64+1 to +2^64-1. Most people learn in school that 64-bit integers range from -2^63 to 2^63-1. Are Tcl's wide integers 65-bit, but then excluding -18446744073709551616? <pre> % expr int(2147483648) ; #on LP64/ILP64 platforms 2147483648 % expr int(2147483648) ; #on other platforms -2147483648 % expr int(9223372036854775808) ; #on LP64/ILP64 platforms -9223372036854775808 % expr int(9223372036854775808) ; #on other platforms 0 % expr wide(9223372036854775808); #all platforms -9223372036854775808 </pre> So, int() does either 32-bit or 64-bit truncation, but the highest left-over bit becomes the sign-bit. wide() does 64-bit truncation. # Specification * On all platforms, the int() math function is modified to do 64-bit truncation, as it already does on [LP64/ILP64](https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models) systems (e.g. 64-bit Linux). int() will thus become synonym for wide(). The wide() function will become deprecated in Tcl 9.0, but it will not be removed yet. * The ranges of "string is integer" and "string is wideinteger" are changed to match the range of the int()/wide() math function. So these functions will report true (1) if the number is in the range -9223372036854775808..9223372036854775807. The "string is wideinteger" command will be deprecated in Tcl 9.0, but it will not be removed yet. * The C function Tcl\_GetIntFromObj() is changed to return TCL\_OK if the Tcl_Obj contains values in the range of 2147483648..4294967295. So, it succeeds if the number fits in either a platform "int", either a platform "unsigned int" type. * The C function Tcl\_GetLongFromObj() is changed to behave like Tcl\_GetIntFromObj() if sizeof(long) == sizeof(ing), and to behave like Tcl\_GetWideIntFromObj() if sizeof(long) == sizeof(Tcl_WideInt) # Implementation Currently, the proposed implementation is available in the [all-wideint branch] (https://core.tcl.tk/tcl/timeline?r=all-wideint). (WIP) # Copyright This document has been placed in the public domain. |