lseq : inconsistent rounding
using a non-integer increment, [lseq] rounding seems to be not consistent: % lseq 4 40 0.1 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.300000000000001 6.4 6.5 6.6 6.7 6.800000000000001 6.9 7.0 7.1 7.2 7.300000000000001 7.4 etc Using a different starting point: % lseq 6 40 0.1 6.0 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 10.0 10.100000000000001 10.2 10.3 etc
878682ff5dFix ticket [63530267aa] by implementing ticket [e5f06285de] and making additional corrections. check-in2024-06-27 09:10:358967d7e9c5Fix ticket [63530267aa] by implementing ticket [e5f06285de] and making additional corrections. check-in2024-06-27 09:00:0009fe59bbbdFix ticket [63530267aa] by implementing ticket [e5f06285de] and making additional corrections. check-in2023-06-28 19:36:4104833e5817Ticket [63530267aa] lseq.test fail on i386 status still Open with 5 other changes ticket2023-06-25 20:04:04
Thanks for the comment. Thanks to Brian to take it and work on it: check-in: [62eaef043c] , branch: [bug-fa00fbbbabe].
Here are my perhaps unrelated comments:
Displaying of a double in decimal is difficult and may have the effects seen here. This might be intentional, as it might be more exact on the double level.
So, lets try manually with TCL 8.6.13:
% expr {4 + 22 * 0.1} 6.2 % expr {4 + 23 * 0.1} 6.300000000000001 % expr {4 + 24 * 0.1} 6.4
So, the calculation is ok. Only the displayed numbers are "ugly" or "surprising", but this is due to the display as decimal of the double data type.
I would at least think twice, if changing this on the display side is an improvement. 6.3 is not equal to 6.300000000000001
So, the result of expr {4 + 23 * 0.1} will not be any more equal to the lseq element.
Harald
Hi Harald!
I appreciate your concerns.
In this case, the long numbers are the result inherent error in converting IEEE floating point representation to decimal, basically, trying to represent a binary number in decimal.
If you work out the math by hand, these extract tiny fractions do not appear.
With careful rounding, the "correct" result can be achieved.
Fix with check-in [a610e50b2faa8c52]
Wow, great !
Then, also
% expr {4 + 23 * 0.1} 6.300000000000001
will also be corrected? Or is corrected in TCl 9.0?
Great ! Harald
Thanks for this fix (and the initial implementation), Brian. Looking forward to start using [lseq]. Harm Olthof
Will this issue be addressed in 8.7, where it is also present?