Repository navigation
[rtext] Fix TextToFloat() rounding and add exponent support - #6313
Open
jayhemnani9910 wants to merge 2 commits into
Open
jayhemnani9910 wants to merge 2 commits into
jayhemnani9910 wants to merge 2 commits into
Conversation
raysan5
reviewed
Oct 21, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TextToFloat()adds each digit to afloatdivided by a growingfloatdivisor, so the rounding error adds up, and it stops ate:Out of 100000 random decimals (up to 5 integer and 7 fraction digits), 26864 differ from
(float)strtod().Up to 9 significant digits are now read into an
unsigned int(later ones only move the decimal point) and scaled once by an exact float power of ten (steps of1e10beyond that), and an optionale/Eexponent is read. No doubles. Still '.' only, and signs, leading text and junk after the number behave as before.Against
strtof(), worst error in ULPs (1 ULP is the gap to the next float):%.9gEdge cases:
1e,e5,.e1,0e999give whatstrtofgives,1e999is inf,1e-45is the smallest subnormal, and every float in [3e38, FLT_MAX) printed with%.9greads back finite. One limit: the 8-digit3.4028235e38rounds up to inf (strtofgives FLT_MAX).