Skip to content

A complex number's modulus is made under the downcasting setting in force - #1619

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
complex-abs-honours-downcasting
Sep 30, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
complex-abs-honours-downcasting

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Complex.Abs() turned the downcasting on to answer a Real. So with the downcasting off, a modulus within its tolerance of a small rational came back as that rational: |75 + 316.22776601683796i|, which is 325 + 2.6e-17, was 325. It now builds the square root under the setting in force, as any other number is made. With the downcasting on nothing changes, since the rounding is the setting's own.

The complex division took its modulus through Abs(), and #1616 gave it a branch of its own for the downcasting off. With Abs() keeping the setting, the division calls it again, and the two agree by construction.

A correction. #1616's code comment, its breaking-changes entry and its test gave that modulus as 325 - 3e-16. It is 325 + 2.6e-17 (mpmath, 150 digits), a relative 8e-20 and not 2e-18. All three are corrected here, and the #1616 description and the #1614 comment have been edited. The fix they describe stands, since the modulus is still within the downcasting's tolerance of 325. The squashed commit message on master keeps the old figure.

Measured

Input Was (2.5.0) Now
"abs(75 + 316.22776601683796i)", downcasting off 325 325.000000000000026076735749…
  • Numeric.AModulusIsMadeUnderTheDowncastingInForce: the modulus with the downcasting off, through Abs() and through abs(...), against mpmath to 90 decimal places; and with it on, 325 as before.
  • The library builds for every target with no warnings, and the unit tests pass: 14,068, none failed (net10.0).
  • The performance gate passes on 4859f91. Allocation matches the baseline on all 19 gated benchmarks. SolveEasy's allocation rose 5.5% when the exact modulus was tried with the downcasting on during The factorial far from zero, and a quotient by a number whose modulus is nearly whole #1616. It is at the baseline's 453,621 B/op.

Closes #1615.

🤖 Generated with Claude Code

…orce

Complex.Abs() turned the downcasting on to answer a Real, so with the downcasting off a modulus
within its tolerance of a small rational came back as that rational: |75 + 316.22776601683796i|,
which is 325 + 2.6e-17, was 325. It now builds the square root under the setting in force, as any
other number is made. With the downcasting on nothing changes: the rounding is the setting's own.

The complex division took its modulus through Abs(), and #1616 gave it a branch of its own for
the downcasting off. With Abs() keeping the setting, the division calls it again, and the two
agree by construction.

#1616's comment, its breaking-changes entry and its test gave that modulus as 325 - 3e-16. It is
325 + 2.6e-17 (mpmath, 150 digits), a relative 8e-20 and not 2e-18, and all three are corrected
here. The fix they describe stands: the modulus is still within the downcasting's tolerance of 325.

Numeric gains the modulus with the downcasting off, through Abs() and through abs(...), against
mpmath to 90 decimal places, and with it on, 325 as before.

Closes #1615.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.6.0 milestone Sep 30, 2026
@Rafael-SOWNet
Rafael-SOWNet merged commit 8cb650e into master Sep 30, 2026
31 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the complex-abs-honours-downcasting branch October 29, 2026 00:43
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.

Complex.Abs() rounds a modulus to a nearby rational with the downcasting off

1 participant