-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compiler: conversion from Infinity to integer is always negative #56023
Comments
Seem happens with On arm64:
|
@cuonglm Thanks, that confirms this is a compiler bug. |
With gccgo the original program prints
|
From the spec:
Which I believe covers this case. We use the instruction From the intel docs, it does:
(I believe that doc is for 32-bit, for 64-bit there are more zeroes.) |
Not that it's a critical case, but it's bothersome how much variation there is between architectures. But "implementation-defined" allows that. At least there were no NaNs involved. |
I don't see anything to fix here, so closing. |
Consider the conversion
I would expect a largest positive integer, but in fact the result is the largest negative integer. I have a feeling the conversion is broken. Perhaps that's what the hardware does, but it's not what the spec claims happens. This negative result happens for all signed integer types, except int8, which yields 0. See
https://go.dev/play/p/TZfBPZzDYbk
which is
This was reported on the mailing list: https://groups.google.com/g/golang-nuts/c/pRUoXRt7syk/m/_jnc1N48DQAJ?utm_medium=email&utm_source=footer&pli=1
I note that in limited testing, C seems to honor the sign.
The text was updated successfully, but these errors were encountered: