Repository navigation
fix(std): avoid intermediate overflow in angle conversions - #963
Merged
LunaStev merged 1 commit intoOct 19, 2026
Merged
Conversation
Multiply degrees and radians by the precomputed scale to keep valid large results finite. Extend shared math regression tests for both float widths, signed zero, small values, and true range overflow. Fixes wavefnd#947 Signed-off-by: hiyouwhatsapp <[email protected]>
LunaStev
approved these changes
Oct 19, 2026
LunaStev
left a comment
Member
There was a problem hiding this comment.
Reviewed the reordered angle-conversion floating-point operations and regression cases for extreme, subnormal, signed-zero, NaN, and infinity inputs. CI passes.
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.
Fixes #947.
Each angle-conversion helper currently multiplies by pi or 180 before dividing. That intermediate product can overflow, even when the converted value is representable. For example,
radians_f64(1e308)produces infinity despite its correct finite magnitude being about1.745e306.Compute the constant scale factor first and multiply once. This avoids intermediate overflow without dividing the input first, which would lose small/subnormal values. The same change applies to all four
f32/f64conversions.Regression coverage
Extended the existing shared math case (
tests/cases/shared/test86.wave) to check:1e-6forf32,1e-12forf64).180°/piconversions.Validation
f32rounding separately, yielded finite results within the stated relative tolerances.No changes to floating-point semantics outside these helpers.