Skip to content

A rational writes its decimal out again in a precision other than the one it kept - #1869

Merged
Rafael-SOWNet merged 3 commits into
masterfrom
a-rational-writes-its-decimal-out-in-the-precision-asked
Oct 13, 2026
Merged

Rafael-SOWNet merged 3 commits into
masterfrom
a-rational-writes-its-decimal-out-in-the-precision-asked

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #1868.

Rational.EDecimal was written out once, in the precision current the first time it was read, and kept from then on. Under a higher DecimalPrecisionContext the rational still answered about a hundred digits, and so did every value computed from it. The integrator checks its answers at the default precision, so every rational in an antiderivative was affected: differentiating a right answer back at 300 or 2,000 digits left the same 1e-102 residual at both precisions. mpmath agrees with the answer to 1e-322.

The cache now holds the context it was written in and is written again under any other context. It is keyed by context instance, as the library's constant cache is. The holder is a struct equal to every other, like the caches on Entity, so two equal rationals stay equal whichever one has been written out.

2.5.0 master a29f7ec branch
Rational.Create(128, 12167).EDecimal read at the default precision, then under 300 digits 100 digits 100 digits 300 digits
sqrt(46) * 128/12167 under 300 digits, with that rational relative error 4.7e-101 relative error 4.1e-101 correct to 300 digits

2.5.0 wrote the decimal out when the rational was made, and master when it was first read; both kept it.

The new test in HighPrecisionFunctionsTest, next to the same test for e (#1367), fails on master and passes here.

Rubi corpus (pocket of all of 1.2.1.5, plus every family): identical on both arms, 0 moves and 0 wrong, as a precision fix should be. The allocation gate passed. The suite passed: 15,303 passed, 0 failed. Master 7ca5b88 is merged in, and the build passes for every target framework.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Rafael-SOWNet and others added 3 commits October 13, 2026 05:57
… one it kept

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>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet Rafael-SOWNet added this to the 2.6.0 milestone Oct 13, 2026
@Rafael-SOWNet
Rafael-SOWNet merged commit 915f742 into master Oct 13, 2026
34 checks passed
@Rafael-SOWNet
Rafael-SOWNet deleted the a-rational-writes-its-decimal-out-in-the-precision-asked branch October 13, 2026 07:26
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 rational evaluated once keeps that precision under a higher one

1 participant