As it will cause printf("%llu\n", (unsigned long long)1e19); output
9223372036854775808
instead of
10000000000000000000
This commit is contained in:
kbkpbot 2024-12-30 12:19:01 +08:00
parent c6afdff7ab
commit eef2db71a9
3 changed files with 4 additions and 4 deletions

View file

@ -3252,10 +3252,7 @@ error:
vtop->c.i = (vtop->c.ld != 0);
} else {
if(sf)
/* the range of [int64_t] is enough to hold the integer part of any float value.
Meanwhile, converting negative double to unsigned integer is UB.
So first convert to [int64_t] here. */
vtop->c.i = (int64_t)vtop->c.ld;
vtop->c.i = vtop->c.ld;
else if (sbt_bt == VT_LLONG || (PTR_SIZE == 8 && sbt == VT_PTR))
;
else if (sbt & VT_UNSIGNED)

View file

@ -7,4 +7,6 @@ int main() {
printf("%d\n", (int)-2147483648.0);
d = -2147483648.0;
printf("%d\n", (int)d);
printf("%llu\n", (unsigned long long)1e19);
}

View file

@ -2,3 +2,4 @@
-1
-2147483648
-2147483648
10000000000000000000