Skip to content

A complex number prints the number it holds, whatever the downcasting setting at printing - #1611

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
complex-prints-what-it-holds
Sep 30, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
complex-prints-what-it-holds

Conversation

@Rafael-SOWNet

@Rafael-SOWNet Rafael-SOWNet commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Printing a complex number with a negative imaginary part negated that part, to print the minus sign before its magnitude. Negating makes a new number, and a new number is downcast under the setting in force when it is made. So a number made with downcasting off printed as another number once downcasting was back on:

made with downcasting off printed with it on reads back as
1 - 0.3333333333333333333333333333333333333333i 1 - 1/3i 1 + i/3
2 - 0.5000000000000000000000000000001i 2 - 1/2i 2 + i/2
erfc(16 - 0.5i), imaginary part -9.4899…E-114 -2.8337…E-113 - 0i the imaginary part lost

The fraction also came out without the product sign it needs beside i, because that sign was decided from the number before the negation. Latexize has the same fault. The library returns such numbers itself as well: Number.Factorial evaluates a complex argument with the downcasting off and returns what it made there.

Both printers now negate with the downcasting off, so the negation is the same number with its sign changed. Under a single setting throughout, nothing prints differently. Real.Create rounds nothing in either mode, and whatever it snaps to an integer or a small rational it snaps the same way at either sign.

Measured

  • StringizeRoundTripTest gains the three numbers above, each made with downcasting off. Each reads back as itself from what Stringize prints, and Latexize prints its imaginary part's magnitude. All three fail without the change, with the readings in the table.
  • The unit suite on 730fd4b (net10.0): 13914 passed, 0 failed. The library builds for every target framework.

Closes #1610.

🤖 Generated with Claude Code

… setting at printing

Printing a complex number with a negative imaginary part negated that part, to print a minus
sign before its magnitude. Negating makes a new number, and a new number is downcast under the
setting in force when it is made. A number made with downcasting off, and printed once it was
back on, printed as another number: 1 - 0.333...i, the decimal to forty digits, as 1 - 1/3i,
a fraction without the product sign it needs, which reads back as 1 + i/3; and the imaginary
part of erfc(16 - 0.5i), -9.49e-114, as 0. Latexize did the same. Such numbers come out of the
library's own downcasting-off scopes as well: the factorial's evaluation and the integrator's
checks open one.

Both printers negate with the downcasting off, so the negation is the same number with its sign
changed. Under one setting throughout nothing prints differently: Real.Create rounds nothing in
either mode, and what it snaps to an integer or a small rational it snaps the same way at either
sign.

StringizeRoundTripTest gains three numbers made with downcasting off. Each reads back as itself
from what Stringize prints, and Latexize prints its imaginary part's magnitude. All three fail
without the change.

Closes #1610.

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 429ace7 into master Sep 30, 2026
31 checks passed
Rafael-SOWNet added a commit that referenced this pull request Oct 9, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Rafael-SOWNet added a commit that referenced this pull request Oct 9, 2026
* Breaking-changes entries for #1828 to #1832 and #1374

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

* And for #1368, #1611 and #1517, each measured on 2.5.0

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

* And for #1289, #1312, #1315, #1377, #1380 and #1371, each measured on 2.5.0

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

A complex number made with downcasting off prints as a different number once downcasting is back on

1 participant