When running the following simple script, I get different outputs
depending on Tcl version and operating system.
Can anyone confirm?
Is it a bug or feature?
Paul
# Linux 8.6.12: 12345678900 -> 12345678900 -> 0XFFFFFFFFDFDC1C34
# Linux 8.7.a5: 12345678900 -> 12345678900 -> 0XFFFFFFFFDFDC1C34
# Windows 8.6.12: -539222988 -> -539222988 -> 0XDFDC1C34
# Windows 8.7.a5: 12345678900 -> -539222988 -> 0XDFDC1C34
set num [expr int(12345678900)]
set bin [binary format i $num]
binary scan $bin i ret
puts "$num -> [format %d $num] -> [format 0X%X $ret]"
exit 0
When running the following simple script, I get different outputs
depending on Tcl version and operating system.
Can anyone confirm?
Is it a bug or feature?
On 21/08/2022 19:31, Paul Obermeier wrote:produces 16 characters, while you only get 8 characters when using 32-bits.
When running the following simple script, I get different outputs depending on Tcl version and operating system.The differences you see seem mostly attributable to a 64-bit tclsh (linux) vs 32-bit tclsh (windows). They are not related to binary strings at all. In all cases the binary scan returns -539222988. But printing a negative number in hex with 64-bits
Can anyone confirm?
Is it a bug or feature?
The other difference between 8.6 and 8.7 on a 32-bit tclsh are due to TIP 514. Before TIP 514, the int() function would cut the number to the native integer size. With your 32-bit tclsh on windows, that produces a negative number. On the 64-bit tclshon linux, enough bits are available to represent the full number. After TIP514, no truncation takes place at all anymore.
Schelte.
On 21/08/2022 19:31, Paul Obermeier wrote:
When running the following simple script, I get different outputs
depending on Tcl version and operating system.
Can anyone confirm?
Is it a bug or feature?
The differences you see seem mostly attributable to a 64-bit tclsh
(linux) vs 32-bit tclsh (windows). They are not related to binary
strings at all. In all cases the binary scan returns -539222988. But
printing a negative number in hex with 64-bits produces 16 characters,
while you only get 8 characters when using 32-bits.
The other difference between 8.6 and 8.7 on a 32-bit tclsh are due to
TIP 514. Before TIP 514, the int() function would cut the number to the native integer size. With your 32-bit tclsh on windows, that produces a negative number. On the 64-bit tclsh on linux, enough bits are available
to represent the full number. After TIP514, no truncation takes place at
all anymore.
Schelte.
With respect to the *platform* differences for the *same* version, I'll term it a feature as it is documented. The docs for int() map it to tcl_platform(wordSize) which in turn maps to the C sizeof(long) which is 32 bits on Windows and 64 bits on Linux.
For 8.7, I would claim it is a bug for the simple reason that it does not stay compatible with 8.6. No idea whether the change is intended or not.
/Ashok
On 8/21/2022 11:01 PM, Paul Obermeier wrote:
When running the following simple script, I get different outputs depending on Tcl version and operating system.
Can anyone confirm?
Is it a bug or feature?
Paul
# Linux 8.6.12: 12345678900 -> 12345678900 -> 0XFFFFFFFFDFDC1C34
# Linux 8.7.a5: 12345678900 -> 12345678900 -> 0XFFFFFFFFDFDC1C34
# Windows 8.6.12: -539222988 -> -539222988 -> 0XDFDC1C34
# Windows 8.7.a5: 12345678900 -> -539222988 -> 0XDFDC1C34
set num [expr int(12345678900)]
set bin [binary format i $num]
binary scan $bin i ret
puts "$num -> [format %d $num] -> [format 0X%X $ret]"
exit 0
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 463 |
Nodes: | 16 (2 / 14) |
Uptime: | 156:52:18 |
Calls: | 9,384 |
Calls today: | 4 |
Files: | 13,561 |
Messages: | 6,095,919 |