Skip to content

fix(std): avoid intermediate overflow in angle conversions - #963

Merged
LunaStev merged 1 commit into
wavefnd:masterfrom
hiyouwhatsapp:fix/947-angle-conversion-overflow
Oct 19, 2026
Merged

LunaStev merged 1 commit into
wavefnd:masterfrom
hiyouwhatsapp:fix/947-angle-conversion-overflow

Conversation

@hiyouwhatsapp

Copy link
Copy Markdown
Contributor

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 about 1.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/f64 conversions.

Regression coverage

Extended the existing shared math case (tests/cases/shared/test86.wave) to check:

  • Large positive and negative degree/radian conversions in both float widths, with relative tolerances (1e-6 for f32, 1e-12 for f64).
  • Ordinary 180°/pi conversions.
  • Negative zero bit preservation and a small-subnormal-input control.
  • Genuine result overflow and NaN/infinity propagation.

Validation

  • Independent floating-point sanity checks for four large values, modeling f32 rounding separately, yielded finite results within the stated relative tolerances.
  • Reviewed the signed-off two-file commit diff and checked trailing whitespace.
  • Wave-native compiler tests are not run locally because this environment lacks the Wave compiler / Rust toolchain. The shared corpus and supported target checks require CI verification.

No changes to floating-point semantics outside these helpers.

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 LunaStev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the reordered angle-conversion floating-point operations and regression cases for extreme, subnormal, signed-zero, NaN, and infinity inputs. CI passes.

@LunaStev
LunaStev merged commit 53e278f into wavefnd:master Oct 19, 2026
35 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.

Avoid intermediate overflow in degree/radian conversions

2 participants