As it will cause printf("%llu\n", (unsigned long long)1e19); output 9223372036854775808 instead of 10000000000000000000
Unified · Split
| @@ -3252,10 +3252,7 @@ error: · 3251 unmodified lines | |||
| 3252 | vtop->c.i = (vtop->c.ld != 0); | 3252 | vtop->c.i = (vtop->c.ld != 0); |
| 3253 | } else { | 3253 | } else { |
| 3254 | if(sf) | 3254 | if(sf) |
| 3255 | /* the range of [int64_t] is enough to hold the integer part of any float value. | 3255 | vtop->c.i = vtop->c.ld; |
| 3256 | Meanwhile, converting negative double to unsigned integer is UB. | ||
| 3257 | So first convert to [int64_t] here. */ | ||
| 3258 | vtop->c.i = (int64_t)vtop->c.ld; | ||
| 3259 | else if (sbt_bt == VT_LLONG || (PTR_SIZE == 8 && sbt == VT_PTR)) | 3256 | else if (sbt_bt == VT_LLONG || (PTR_SIZE == 8 && sbt == VT_PTR)) |
| 3260 | ; | 3257 | ; |
| 3261 | else if (sbt & VT_UNSIGNED) | 3258 | else if (sbt & VT_UNSIGNED) |
| @@ -7,4 +7,6 @@ int main() { · 6 unmodified lines | |||
| 7 | printf("%d\n", (int)-2147483648.0); | 7 | printf("%d\n", (int)-2147483648.0); |
| 8 | d = -2147483648.0; | 8 | d = -2147483648.0; |
| 9 | printf("%d\n", (int)d); | 9 | printf("%d\n", (int)d); |
| 10 | |||
| 11 | printf("%llu\n", (unsigned long long)1e19); | ||
| 10 | } | 12 | } |
| @@ -2,3 +2,4 @@ · 1 unmodified line | |||
| 2 | -1 | 2 | -1 |
| 3 | -2147483648 | 3 | -2147483648 |
| 4 | -2147483648 | 4 | -2147483648 |
| 5 | 10000000000000000000 | ||