* [9front] Bug converting vlong to double on 32bit architectures
@ 2022-12-30 13:19 cosarara
2022-12-30 16:57 ` Jaume Delclòs Coll
2022-12-30 18:32 ` cinap_lenrek
0 siblings, 2 replies; 3+ messages in thread
From: cosarara @ 2022-12-30 13:19 UTC (permalink / raw)
To: 9front
Hi,
While trying to run kvik's lu9 on ARM, I found that when converting
LLONG_MIN to a double on 32bit systems, the result is wrong (positive
instead of negative).
Given the following test program:
#include <u.h>
#include <libc.h>
#define LLONG_MAX
#define LLONG_MIN (-LLONG_MAX-1)
void main() {
vlong min = LLONG_MIN;
double dmin = min;
print("minint %lld\n", min);
print("minint as double %f\n", dmin);
if (dmin > 0.0) {
exits("int min as double turned positive");
}
exits(0);
}
The output on x86_64 will be:
minint -9223372036854775808
minint as double -9223372036854776400.000000
But on arm or 386 (and I expect also spim, 68000, mips, 68020, sparc,
power, since they all use the same _v2d):
minint -9223372036854775808
minint as double 9223372036854776400.000000
And the value turned positive in the conversion.
The function used for the cast to double is (in /sys/src/libc/arm/vlrt.c):
#define SIGN(n) (1UL<<(n-1))
double
_v2d(Vlong x)
{
if(x.hi & SIGN(32)) {
if(x.lo) {
x.lo = -x.lo;
x.hi = ~x.hi;
} else
x.hi = -x.hi;
return -((long)x.hi*4294967296. + x.lo);
}
return (long)x.hi*4294967296. + x.lo;
}
If I understand correctly, the issue is that where it tries to flip the
sign for x.hi (x.hi = -x.hi), 0x80000000 has no positive, thus stays the
same (it stays negative). Then when we get to the negative return, we
get a positive out.
What came to my mind then, is that in the case that there is no x.lo, we
can keep the x.hi sign and cast directly, thus:
double
_v2d(Vlong x)
{
if(!x.lo) {
return (long)x.hi*4294967296.;
}
if(x.hi & SIGN(32)) {
x.lo = -x.lo;
x.hi = ~x.hi;
return -((long)x.hi*4294967296. + x.lo);
}
return (long)x.hi*4294967296. + x.lo;
}
This looks correct to me, but I don't trust myself to not make mistakes
in such critical code, so I would like some feedback on the change.
Happy new year in advance,
cosa
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] Bug converting vlong to double on 32bit architectures
2022-12-30 13:19 [9front] Bug converting vlong to double on 32bit architectures cosarara
@ 2022-12-30 16:57 ` Jaume Delclòs Coll
2022-12-30 18:32 ` cinap_lenrek
1 sibling, 0 replies; 3+ messages in thread
From: Jaume Delclòs Coll @ 2022-12-30 16:57 UTC (permalink / raw)
To: 9front
On 30/12/22 14:19, cosarara wrote:
> #define LLONG_MAX
> #define LLONG_MIN (-LLONG_MAX-1)
This was supposed to be
#define LLONG_MAX 0x7fffffffffffffffLL
#define LLONG_MIN (-LLONG_MAX-1)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9front] Bug converting vlong to double on 32bit architectures
2022-12-30 13:19 [9front] Bug converting vlong to double on 32bit architectures cosarara
2022-12-30 16:57 ` Jaume Delclòs Coll
@ 2022-12-30 18:32 ` cinap_lenrek
1 sibling, 0 replies; 3+ messages in thread
From: cinap_lenrek @ 2022-12-30 18:32 UTC (permalink / raw)
To: 9front
i tested this on arm (aijuboard) and 386 (vmx) and it works fine.
i'll make a patch.
i wrote a little test program testing all the powers of two
+1 -1 negation and inverstion.
so looks good to me.
--
cinap
PS:
( 1) 1 -> 1.000000 (1.000000e+00)
( 2) 2 -> 2.000000 (2.000000e+00)
( 0) 0 -> 0.000000 (0.000000e+00)
( -1) -1 -> -1.000000 (-1.000000e+00)
( -2) -2 -> -2.000000 (-2.000000e+00)
( 2) 2 -> 2.000000 (2.000000e+00)
( 3) 3 -> 3.000000 (3.000000e+00)
( 1) 1 -> 1.000000 (1.000000e+00)
( -2) -2 -> -2.000000 (-2.000000e+00)
( -3) -3 -> -3.000000 (-3.000000e+00)
( 4) 4 -> 4.000000 (4.000000e+00)
( 5) 5 -> 5.000000 (5.000000e+00)
( 3) 3 -> 3.000000 (3.000000e+00)
( -4) -4 -> -4.000000 (-4.000000e+00)
( -5) -5 -> -5.000000 (-5.000000e+00)
( 8) 8 -> 8.000000 (8.000000e+00)
( 9) 9 -> 9.000000 (9.000000e+00)
( 7) 7 -> 7.000000 (7.000000e+00)
( -8) -8 -> -8.000000 (-8.000000e+00)
( -9) -9 -> -9.000000 (-9.000000e+00)
( 10) 16 -> 16.000000 (1.600000e+01)
( 11) 17 -> 17.000000 (1.700000e+01)
( f) 15 -> 15.000000 (1.500000e+01)
( -10) -16 -> -16.000000 (-1.600000e+01)
( -11) -17 -> -17.000000 (-1.700000e+01)
( 20) 32 -> 32.000000 (3.200000e+01)
( 21) 33 -> 33.000000 (3.300000e+01)
( 1f) 31 -> 31.000000 (3.100000e+01)
( -20) -32 -> -32.000000 (-3.200000e+01)
( -21) -33 -> -33.000000 (-3.300000e+01)
( 40) 64 -> 64.000000 (6.400000e+01)
( 41) 65 -> 65.000000 (6.500000e+01)
( 3f) 63 -> 63.000000 (6.300000e+01)
( -40) -64 -> -64.000000 (-6.400000e+01)
( -41) -65 -> -65.000000 (-6.500000e+01)
( 80) 128 -> 128.000000 (1.280000e+02)
( 81) 129 -> 129.000000 (1.290000e+02)
( 7f) 127 -> 127.000000 (1.270000e+02)
( -80) -128 -> -128.000000 (-1.280000e+02)
( -81) -129 -> -129.000000 (-1.290000e+02)
( 100) 256 -> 256.000000 (2.560000e+02)
( 101) 257 -> 257.000000 (2.570000e+02)
( ff) 255 -> 255.000000 (2.550000e+02)
( -100) -256 -> -256.000000 (-2.560000e+02)
( -101) -257 -> -257.000000 (-2.570000e+02)
( 200) 512 -> 512.000000 (5.120000e+02)
( 201) 513 -> 513.000000 (5.130000e+02)
( 1ff) 511 -> 511.000000 (5.110000e+02)
( -200) -512 -> -512.000000 (-5.120000e+02)
( -201) -513 -> -513.000000 (-5.130000e+02)
( 400) 1024 -> 1024.000000 (1.024000e+03)
( 401) 1025 -> 1025.000000 (1.025000e+03)
( 3ff) 1023 -> 1023.000000 (1.023000e+03)
( -400) -1024 -> -1024.000000 (-1.024000e+03)
( -401) -1025 -> -1025.000000 (-1.025000e+03)
( 800) 2048 -> 2048.000000 (2.048000e+03)
( 801) 2049 -> 2049.000000 (2.049000e+03)
( 7ff) 2047 -> 2047.000000 (2.047000e+03)
( -800) -2048 -> -2048.000000 (-2.048000e+03)
( -801) -2049 -> -2049.000000 (-2.049000e+03)
( 1000) 4096 -> 4096.000000 (4.096000e+03)
( 1001) 4097 -> 4097.000000 (4.097000e+03)
( fff) 4095 -> 4095.000000 (4.095000e+03)
( -1000) -4096 -> -4096.000000 (-4.096000e+03)
( -1001) -4097 -> -4097.000000 (-4.097000e+03)
( 2000) 8192 -> 8192.000000 (8.192000e+03)
( 2001) 8193 -> 8193.000000 (8.193000e+03)
( 1fff) 8191 -> 8191.000000 (8.191000e+03)
( -2000) -8192 -> -8192.000000 (-8.192000e+03)
( -2001) -8193 -> -8193.000000 (-8.193000e+03)
( 4000) 16384 -> 16384.000000 (1.638400e+04)
( 4001) 16385 -> 16385.000000 (1.638500e+04)
( 3fff) 16383 -> 16383.000000 (1.638300e+04)
( -4000) -16384 -> -16384.000000 (-1.638400e+04)
( -4001) -16385 -> -16385.000000 (-1.638500e+04)
( 8000) 32768 -> 32768.000000 (3.276800e+04)
( 8001) 32769 -> 32769.000000 (3.276900e+04)
( 7fff) 32767 -> 32767.000000 (3.276700e+04)
( -8000) -32768 -> -32768.000000 (-3.276800e+04)
( -8001) -32769 -> -32769.000000 (-3.276900e+04)
( 10000) 65536 -> 65536.000000 (6.553600e+04)
( 10001) 65537 -> 65537.000000 (6.553700e+04)
( ffff) 65535 -> 65535.000000 (6.553500e+04)
( -10000) -65536 -> -65536.000000 (-6.553600e+04)
( -10001) -65537 -> -65537.000000 (-6.553700e+04)
( 20000) 131072 -> 131072.000000 (1.310720e+05)
( 20001) 131073 -> 131073.000000 (1.310730e+05)
( 1ffff) 131071 -> 131071.000000 (1.310710e+05)
( -20000) -131072 -> -131072.000000 (-1.310720e+05)
( -20001) -131073 -> -131073.000000 (-1.310730e+05)
( 40000) 262144 -> 262144.000000 (2.621440e+05)
( 40001) 262145 -> 262145.000000 (2.621450e+05)
( 3ffff) 262143 -> 262143.000000 (2.621430e+05)
( -40000) -262144 -> -262144.000000 (-2.621440e+05)
( -40001) -262145 -> -262145.000000 (-2.621450e+05)
( 80000) 524288 -> 524288.000000 (5.242880e+05)
( 80001) 524289 -> 524289.000000 (5.242890e+05)
( 7ffff) 524287 -> 524287.000000 (5.242870e+05)
( -80000) -524288 -> -524288.000000 (-5.242880e+05)
( -80001) -524289 -> -524289.000000 (-5.242890e+05)
( 100000) 1048576 -> 1048576.000000 (1.048576e+06)
( 100001) 1048577 -> 1048577.000000 (1.048577e+06)
( fffff) 1048575 -> 1048575.000000 (1.048575e+06)
( -100000) -1048576 -> -1048576.000000 (-1.048576e+06)
( -100001) -1048577 -> -1048577.000000 (-1.048577e+06)
( 200000) 2097152 -> 2097152.000000 (2.097152e+06)
( 200001) 2097153 -> 2097153.000000 (2.097153e+06)
( 1fffff) 2097151 -> 2097151.000000 (2.097151e+06)
( -200000) -2097152 -> -2097152.000000 (-2.097152e+06)
( -200001) -2097153 -> -2097153.000000 (-2.097153e+06)
( 400000) 4194304 -> 4194304.000000 (4.194304e+06)
( 400001) 4194305 -> 4194305.000000 (4.194305e+06)
( 3fffff) 4194303 -> 4194303.000000 (4.194303e+06)
( -400000) -4194304 -> -4194304.000000 (-4.194304e+06)
( -400001) -4194305 -> -4194305.000000 (-4.194305e+06)
( 800000) 8388608 -> 8388608.000000 (8.388608e+06)
( 800001) 8388609 -> 8388609.000000 (8.388609e+06)
( 7fffff) 8388607 -> 8388607.000000 (8.388607e+06)
( -800000) -8388608 -> -8388608.000000 (-8.388608e+06)
( -800001) -8388609 -> -8388609.000000 (-8.388609e+06)
( 1000000) 16777216 -> 16777216.000000 (1.677722e+07)
( 1000001) 16777217 -> 16777217.000000 (1.677722e+07)
( ffffff) 16777215 -> 16777215.000000 (1.677722e+07)
( -1000000) -16777216 -> -16777216.000000 (-1.677722e+07)
( -1000001) -16777217 -> -16777217.000000 (-1.677722e+07)
( 2000000) 33554432 -> 33554432.000000 (3.355443e+07)
( 2000001) 33554433 -> 33554433.000000 (3.355443e+07)
( 1ffffff) 33554431 -> 33554431.000000 (3.355443e+07)
( -2000000) -33554432 -> -33554432.000000 (-3.355443e+07)
( -2000001) -33554433 -> -33554433.000000 (-3.355443e+07)
( 4000000) 67108864 -> 67108864.000000 (6.710886e+07)
( 4000001) 67108865 -> 67108865.000000 (6.710886e+07)
( 3ffffff) 67108863 -> 67108863.000000 (6.710886e+07)
( -4000000) -67108864 -> -67108864.000000 (-6.710886e+07)
( -4000001) -67108865 -> -67108865.000000 (-6.710886e+07)
( 8000000) 134217728 -> 134217728.000000 (1.342177e+08)
( 8000001) 134217729 -> 134217729.000000 (1.342177e+08)
( 7ffffff) 134217727 -> 134217727.000000 (1.342177e+08)
( -8000000) -134217728 -> -134217728.000000 (-1.342177e+08)
( -8000001) -134217729 -> -134217729.000000 (-1.342177e+08)
( 10000000) 268435456 -> 268435456.000000 (2.684355e+08)
( 10000001) 268435457 -> 268435457.000000 (2.684355e+08)
( fffffff) 268435455 -> 268435455.000000 (2.684355e+08)
( -10000000) -268435456 -> -268435456.000000 (-2.684355e+08)
( -10000001) -268435457 -> -268435457.000000 (-2.684355e+08)
( 20000000) 536870912 -> 536870912.000000 (5.368709e+08)
( 20000001) 536870913 -> 536870913.000000 (5.368709e+08)
( 1fffffff) 536870911 -> 536870911.000000 (5.368709e+08)
( -20000000) -536870912 -> -536870912.000000 (-5.368709e+08)
( -20000001) -536870913 -> -536870913.000000 (-5.368709e+08)
( 40000000) 1073741824 -> 1073741824.000000 (1.073742e+09)
( 40000001) 1073741825 -> 1073741825.000000 (1.073742e+09)
( 3fffffff) 1073741823 -> 1073741823.000000 (1.073742e+09)
( -40000000) -1073741824 -> -1073741824.000000 (-1.073742e+09)
( -40000001) -1073741825 -> -1073741825.000000 (-1.073742e+09)
( 80000000) 2147483648 -> 2147483648.000000 (2.147484e+09)
( 80000001) 2147483649 -> 2147483649.000000 (2.147484e+09)
( 7fffffff) 2147483647 -> 2147483647.000000 (2.147484e+09)
( -80000000) -2147483648 -> -2147483648.000000 (-2.147484e+09)
( -80000001) -2147483649 -> -2147483649.000000 (-2.147484e+09)
( 100000000) 4294967296 -> 4294967296.000000 (4.294967e+09)
( 100000001) 4294967297 -> 4294967297.000000 (4.294967e+09)
( ffffffff) 4294967295 -> 4294967295.000000 (4.294967e+09)
( -100000000) -4294967296 -> -4294967296.000000 (-4.294967e+09)
( -100000001) -4294967297 -> -4294967297.000000 (-4.294967e+09)
( 200000000) 8589934592 -> 8589934592.000000 (8.589935e+09)
( 200000001) 8589934593 -> 8589934593.000000 (8.589935e+09)
( 1ffffffff) 8589934591 -> 8589934591.000000 (8.589935e+09)
( -200000000) -8589934592 -> -8589934592.000000 (-8.589935e+09)
( -200000001) -8589934593 -> -8589934593.000000 (-8.589935e+09)
( 400000000) 17179869184 -> 17179869184.000000 (1.717987e+10)
( 400000001) 17179869185 -> 17179869185.000000 (1.717987e+10)
( 3ffffffff) 17179869183 -> 17179869183.000000 (1.717987e+10)
( -400000000) -17179869184 -> -17179869184.000000 (-1.717987e+10)
( -400000001) -17179869185 -> -17179869185.000000 (-1.717987e+10)
( 800000000) 34359738368 -> 34359738368.000000 (3.435974e+10)
( 800000001) 34359738369 -> 34359738369.000000 (3.435974e+10)
( 7ffffffff) 34359738367 -> 34359738367.000000 (3.435974e+10)
( -800000000) -34359738368 -> -34359738368.000000 (-3.435974e+10)
( -800000001) -34359738369 -> -34359738369.000000 (-3.435974e+10)
( 1000000000) 68719476736 -> 68719476736.000000 (6.871948e+10)
( 1000000001) 68719476737 -> 68719476737.000000 (6.871948e+10)
( fffffffff) 68719476735 -> 68719476735.000000 (6.871948e+10)
( -1000000000) -68719476736 -> -68719476736.000000 (-6.871948e+10)
( -1000000001) -68719476737 -> -68719476737.000000 (-6.871948e+10)
( 2000000000) 137438953472 -> 137438953472.000000 (1.374390e+11)
( 2000000001) 137438953473 -> 137438953473.000000 (1.374390e+11)
( 1fffffffff) 137438953471 -> 137438953471.000000 (1.374390e+11)
( -2000000000) -137438953472 -> -137438953472.000000 (-1.374390e+11)
( -2000000001) -137438953473 -> -137438953473.000000 (-1.374390e+11)
( 4000000000) 274877906944 -> 274877906944.000000 (2.748779e+11)
( 4000000001) 274877906945 -> 274877906945.000000 (2.748779e+11)
( 3fffffffff) 274877906943 -> 274877906943.000000 (2.748779e+11)
( -4000000000) -274877906944 -> -274877906944.000000 (-2.748779e+11)
( -4000000001) -274877906945 -> -274877906945.000000 (-2.748779e+11)
( 8000000000) 549755813888 -> 549755813888.000000 (5.497558e+11)
( 8000000001) 549755813889 -> 549755813889.000000 (5.497558e+11)
( 7fffffffff) 549755813887 -> 549755813887.000000 (5.497558e+11)
( -8000000000) -549755813888 -> -549755813888.000000 (-5.497558e+11)
( -8000000001) -549755813889 -> -549755813889.000000 (-5.497558e+11)
( 10000000000) 1099511627776 -> 1099511627776.000000 (1.099512e+12)
( 10000000001) 1099511627777 -> 1099511627777.000000 (1.099512e+12)
( ffffffffff) 1099511627775 -> 1099511627775.000000 (1.099512e+12)
( -10000000000) -1099511627776 -> -1099511627776.000000 (-1.099512e+12)
( -10000000001) -1099511627777 -> -1099511627777.000000 (-1.099512e+12)
( 20000000000) 2199023255552 -> 2199023255552.000000 (2.199023e+12)
( 20000000001) 2199023255553 -> 2199023255553.000000 (2.199023e+12)
( 1ffffffffff) 2199023255551 -> 2199023255551.000000 (2.199023e+12)
( -20000000000) -2199023255552 -> -2199023255552.000000 (-2.199023e+12)
( -20000000001) -2199023255553 -> -2199023255553.000000 (-2.199023e+12)
( 40000000000) 4398046511104 -> 4398046511104.000000 (4.398047e+12)
( 40000000001) 4398046511105 -> 4398046511105.000000 (4.398047e+12)
( 3ffffffffff) 4398046511103 -> 4398046511103.000000 (4.398047e+12)
( -40000000000) -4398046511104 -> -4398046511104.000000 (-4.398047e+12)
( -40000000001) -4398046511105 -> -4398046511105.000000 (-4.398047e+12)
( 80000000000) 8796093022208 -> 8796093022208.000000 (8.796093e+12)
( 80000000001) 8796093022209 -> 8796093022209.000000 (8.796093e+12)
( 7ffffffffff) 8796093022207 -> 8796093022207.000000 (8.796093e+12)
( -80000000000) -8796093022208 -> -8796093022208.000000 (-8.796093e+12)
( -80000000001) -8796093022209 -> -8796093022209.000000 (-8.796093e+12)
( 100000000000) 17592186044416 -> 17592186044416.000000 (1.759219e+13)
( 100000000001) 17592186044417 -> 17592186044417.000000 (1.759219e+13)
( fffffffffff) 17592186044415 -> 17592186044415.000000 (1.759219e+13)
( -100000000000) -17592186044416 -> -17592186044416.000000 (-1.759219e+13)
( -100000000001) -17592186044417 -> -17592186044417.000000 (-1.759219e+13)
( 200000000000) 35184372088832 -> 35184372088832.000000 (3.518437e+13)
( 200000000001) 35184372088833 -> 35184372088833.000000 (3.518437e+13)
( 1fffffffffff) 35184372088831 -> 35184372088831.000000 (3.518437e+13)
( -200000000000) -35184372088832 -> -35184372088832.000000 (-3.518437e+13)
( -200000000001) -35184372088833 -> -35184372088833.000000 (-3.518437e+13)
( 400000000000) 70368744177664 -> 70368744177664.000000 (7.036874e+13)
( 400000000001) 70368744177665 -> 70368744177665.000000 (7.036874e+13)
( 3fffffffffff) 70368744177663 -> 70368744177663.000000 (7.036874e+13)
( -400000000000) -70368744177664 -> -70368744177664.000000 (-7.036874e+13)
( -400000000001) -70368744177665 -> -70368744177665.000000 (-7.036874e+13)
( 800000000000) 140737488355328 -> 140737488355328.000000 (1.407375e+14)
( 800000000001) 140737488355329 -> 140737488355329.000000 (1.407375e+14)
( 7fffffffffff) 140737488355327 -> 140737488355327.000000 (1.407375e+14)
( -800000000000) -140737488355328 -> -140737488355328.000000 (-1.407375e+14)
( -800000000001) -140737488355329 -> -140737488355329.000000 (-1.407375e+14)
( 1000000000000) 281474976710656 -> 281474976710656.000000 (2.814750e+14)
( 1000000000001) 281474976710657 -> 281474976710657.000000 (2.814750e+14)
( ffffffffffff) 281474976710655 -> 281474976710655.000000 (2.814750e+14)
( -1000000000000) -281474976710656 -> -281474976710656.000000 (-2.814750e+14)
( -1000000000001) -281474976710657 -> -281474976710657.000000 (-2.814750e+14)
( 2000000000000) 562949953421312 -> 562949953421312.000000 (5.629500e+14)
( 2000000000001) 562949953421313 -> 562949953421313.000000 (5.629500e+14)
( 1ffffffffffff) 562949953421311 -> 562949953421311.000000 (5.629500e+14)
( -2000000000000) -562949953421312 -> -562949953421312.000000 (-5.629500e+14)
( -2000000000001) -562949953421313 -> -562949953421313.000000 (-5.629500e+14)
( 4000000000000) 1125899906842624 -> 1125899906842624.000000 (1.125900e+15)
( 4000000000001) 1125899906842625 -> 1125899906842625.100000 (1.125900e+15)
( 3ffffffffffff) 1125899906842623 -> 1125899906842623.000000 (1.125900e+15)
( -4000000000000) -1125899906842624 -> -1125899906842624.000000 (-1.125900e+15)
( -4000000000001) -1125899906842625 -> -1125899906842625.100000 (-1.125900e+15)
( 8000000000000) 2251799813685248 -> 2251799813685248.100000 (2.251800e+15)
( 8000000000001) 2251799813685249 -> 2251799813685249.000000 (2.251800e+15)
( 7ffffffffffff) 2251799813685247 -> 2251799813685247.100000 (2.251800e+15)
( -8000000000000) -2251799813685248 -> -2251799813685248.100000 (-2.251800e+15)
( -8000000000001) -2251799813685249 -> -2251799813685249.000000 (-2.251800e+15)
( 10000000000000) 4503599627370496 -> 4503599627370496.300000 (4.503600e+15)
( 10000000000001) 4503599627370497 -> 4503599627370497.200000 (4.503600e+15)
( fffffffffffff) 4503599627370495 -> 4503599627370495.200000 (4.503600e+15)
( -10000000000000) -4503599627370496 -> -4503599627370496.300000 (-4.503600e+15)
( -10000000000001) -4503599627370497 -> -4503599627370497.200000 (-4.503600e+15)
( 20000000000000) 9007199254740992 -> 9007199254740992.600000 (9.007199e+15)
( 20000000000001) 9007199254740993 -> 9007199254740992.600000 (9.007199e+15)
( 1fffffffffffff) 9007199254740991 -> 9007199254740990.900000 (9.007199e+15)
( -20000000000000) -9007199254740992 -> -9007199254740992.600000 (-9.007199e+15)
( -20000000000001) -9007199254740993 -> -9007199254740992.600000 (-9.007199e+15)
( 40000000000000) 18014398509481984 -> 18014398509481983.000000 (1.801440e+16)
( 40000000000001) 18014398509481985 -> 18014398509481983.000000 (1.801440e+16)
( 3fffffffffffff) 18014398509481983 -> 18014398509481983.000000 (1.801440e+16)
( -40000000000000) -18014398509481984 -> -18014398509481983.000000 (-1.801440e+16)
( -40000000000001) -18014398509481985 -> -18014398509481983.000000 (-1.801440e+16)
( 80000000000000) 36028797018963968 -> 36028797018963967.000000 (3.602880e+16)
( 80000000000001) 36028797018963969 -> 36028797018963967.000000 (3.602880e+16)
( 7fffffffffffff) 36028797018963967 -> 36028797018963967.000000 (3.602880e+16)
( -80000000000000) -36028797018963968 -> -36028797018963967.000000 (-3.602880e+16)
( -80000000000001) -36028797018963969 -> -36028797018963967.000000 (-3.602880e+16)
( 100000000000000) 72057594037927936 -> 72057594037927934.000000 (7.205759e+16)
( 100000000000001) 72057594037927937 -> 72057594037927934.000000 (7.205759e+16)
( ffffffffffffff) 72057594037927935 -> 72057594037927934.000000 (7.205759e+16)
(-100000000000000) -72057594037927936 -> -72057594037927934.000000 (-7.205759e+16)
(-100000000000001) -72057594037927937 -> -72057594037927934.000000 (-7.205759e+16)
( 200000000000000) 144115188075855872 -> 144115188075855880.000000 (1.441152e+17)
( 200000000000001) 144115188075855873 -> 144115188075855880.000000 (1.441152e+17)
( 1ffffffffffffff) 144115188075855871 -> 144115188075855880.000000 (1.441152e+17)
(-200000000000000) -144115188075855872 -> -144115188075855880.000000 (-1.441152e+17)
(-200000000000001) -144115188075855873 -> -144115188075855880.000000 (-1.441152e+17)
( 400000000000000) 288230376151711744 -> 288230376151711770.000000 (2.882304e+17)
( 400000000000001) 288230376151711745 -> 288230376151711770.000000 (2.882304e+17)
( 3ffffffffffffff) 288230376151711743 -> 288230376151711770.000000 (2.882304e+17)
(-400000000000000) -288230376151711744 -> -288230376151711770.000000 (-2.882304e+17)
(-400000000000001) -288230376151711745 -> -288230376151711770.000000 (-2.882304e+17)
( 800000000000000) 576460752303423488 -> 576460752303423520.000000 (5.764608e+17)
( 800000000000001) 576460752303423489 -> 576460752303423520.000000 (5.764608e+17)
( 7ffffffffffffff) 576460752303423487 -> 576460752303423520.000000 (5.764608e+17)
(-800000000000000) -576460752303423488 -> -576460752303423520.000000 (-5.764608e+17)
(-800000000000001) -576460752303423489 -> -576460752303423520.000000 (-5.764608e+17)
(1000000000000000) 1152921504606846976 -> 1152921504606847000.000000 (1.152922e+18)
(1000000000000001) 1152921504606846977 -> 1152921504606847000.000000 (1.152922e+18)
( fffffffffffffff) 1152921504606846975 -> 1152921504606847000.000000 (1.152922e+18)
(-1000000000000000) -1152921504606846976 -> -1152921504606847000.000000 (-1.152922e+18)
(-1000000000000001) -1152921504606846977 -> -1152921504606847000.000000 (-1.152922e+18)
(2000000000000000) 2305843009213693952 -> 2305843009213694100.000000 (2.305843e+18)
(2000000000000001) 2305843009213693953 -> 2305843009213694100.000000 (2.305843e+18)
(1fffffffffffffff) 2305843009213693951 -> 2305843009213694100.000000 (2.305843e+18)
(-2000000000000000) -2305843009213693952 -> -2305843009213694100.000000 (-2.305843e+18)
(-2000000000000001) -2305843009213693953 -> -2305843009213694100.000000 (-2.305843e+18)
(4000000000000000) 4611686018427387904 -> 4611686018427388200.000000 (4.611686e+18)
(4000000000000001) 4611686018427387905 -> 4611686018427388200.000000 (4.611686e+18)
(3fffffffffffffff) 4611686018427387903 -> 4611686018427388200.000000 (4.611686e+18)
(-4000000000000000) -4611686018427387904 -> -4611686018427388200.000000 (-4.611686e+18)
(-4000000000000001) -4611686018427387905 -> -4611686018427388200.000000 (-4.611686e+18)
(-8000000000000000) -9223372036854775808 -> -9223372036854776400.000000 (-9.223372e+18)
(-7fffffffffffffff) -9223372036854775807 -> -9223372036854776400.000000 (-9.223372e+18)
(7fffffffffffffff) 9223372036854775807 -> 9223372036854776400.000000 (9.223372e+18)
(-8000000000000000) -9223372036854775808 -> -9223372036854776400.000000 (-9.223372e+18)
(7fffffffffffffff) 9223372036854775807 -> 9223372036854776400.000000 (9.223372e+18)
----
#include <u.h>
#include <libc.h>
double
conv(vlong v)
{
return (double)v;
}
void
test1(vlong v)
{
double d = conv(v);
print("(%16llx) %20lld -> %f (%e)\n", v, v, d, d);
if(v < 0)
assert(d < 0);
else
assert(d >= 0);
}
void
test(vlong v)
{
test1(v);
test1(v+1);
test1(v-1);
test1(-v);
test1(~v);
}
void
main(void)
{
int i;
for(i = 0; i < 64; i++)
test(1LL<<i);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-30 18:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-30 13:19 [9front] Bug converting vlong to double on 32bit architectures cosarara
2022-12-30 16:57 ` Jaume Delclòs Coll
2022-12-30 18:32 ` cinap_lenrek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).