Skip to content

Conversation

toughengineer
Copy link
Contributor

Adding corner cases for rounding to max value or infinity according to the following comment:

@toughengineer Your statement is anything greater than the maximum value (FLT_MAX in this case) overflows to infinity. That's correct, although we first have to apply rounding.

So the last few large 32-bit numbers are $2^{127} \times (2 - 3\times 2^{-23}) $, $2^{127} \times (2 - 2\times 2^{-23}) $, $2^{127} \times (2 - 2^{-23}) $. The next number in the sequence would be $2^{128} $ but it is outside the scope. We round the number strings. Up to the midpoint between $2^{127} \times (2 - 2^{-23})$ and $2^{128} $, we round down to $2^{127} \times (2 - 2^{-23})$, then we round up (virtually) to $2^{128} $, falling into infinity.

The smallest numbers that will round to infinity are

  • (32 bits) $2^{127} \times (2 - 1/2 \times 2^{-23})$ or 340282356779733661637539395458142568448.0f
  • (64 bits) $2^{1023} \times (2 - 1/2 \times 2^{-52})$ or 179769313486231580793728971405303415079934132710037826936173778980444968292764750946649017977587207096330286416692887910946555547851940402630657488671505820681908902000708383676273854845817711531764475730270069855571366959622842914819860834936475292719074168444365510704342711559699508093042880177904174497792.0

Originally posted by @lemire in #328 (comment)

@lemire lemire merged commit 24fa687 into fastfloat:main Oct 4, 2025
37 checks passed
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

Successfully merging this pull request may close these issues.

2 participants