You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hypot(3e1500000000, 4e1500000000) throws OverflowException instead of returning 5e1500000000, and Hypot(1e100000, 1) takes almost a second #155
The operands are squared without being scaled first. Multiply (PreciseNumber.cs, around line 1572) computes checked(left.Exponent + right.Exponent), so squaring any value with |exponent| above about 1.07e9 throws.
The remark on Hypot (around lines 186-191) says the scaling a double implementation needs is unnecessary because "a PreciseNumber has no such range". That isn't true, because Exponent is an int. Neither overload documents an OverflowException.
Hypot(3e1500000000, 4e1500000000) throws OverflowException. The correct result, 5e1500000000, can be represented, and Sqrt(9e2000000000) returns 3e1000000000 without trouble.
Hypot(1e100000, 1) takes about 840 ms, and Hypot(1e20000, 1) about 73 ms. Squaring followed by exponent alignment in Add builds an integer of roughly 2×10⁵ digits, then runs a Newton square root on it. The answer at default precision is just 1e100000.
Related but distinct: #149, #150 and #133 cover the same family of extreme-exponent cost and overflow problems in Sin/Exp, Exp2 and ExpM1. None of them covers Hypot.
Suggested fix
Shift both operands by the larger operand's exponent so the larger is near 10⁰. Compute hypot, then shift the result back with ShiftExponent. Exact results stay exact.
If the smaller operand is more than significantDigits plus a guard below the larger, return |larger| rounded to significantDigits without doing any arithmetic.
Correct the remark, and document any remaining OverflowException.
Priority: Low. It needs exponents beyond about 1e9 to throw, or about 1e4 to get slow, and the failure is a loud exception rather than a wrong value. The incorrect XML remark should still be corrected.
Area / suggested assignment: Roots and transcendentals, in PreciseNumber.Roots.csHypot. Scale by the larger exponent and short-circuit when the smaller operand is negligible.
Activity
matt-edmondson commentedon Oct 6, 2026
Triage
PreciseNumber.Roots.csHypot. Scale by the larger exponent and short-circuit when the smaller operand is negligible.Generated by Claude Code