Skip to content

LibC: Casting a large enough long double to double and printing it results in an infinite loop. #25829

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

Open
hiperbolt opened this issue Mar 24, 2025 · 0 comments

Comments

@hiperbolt
Copy link

When casting a long double that overflows the double-precision floating point exponent range (10^308) to double and trying to print it, it results in an infinite print loop:

Image

Looking at the binary representation, it seems the casting is going very wrong:

Image

With an exponent smaller than 308 this doesn't happen, however the lack of precision is extremely high, which might be a bug on its own:

Image

For comparison, with glibc, casting a long double to overflowing double results in "inf" and the precision is much higher:

Image

Maybe we should go with the glibc approach and print "inf" in these cases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant