Exact remainders; refuse numbers held rounded (closes #3)
check / check (push) Successful in 1m14s

x % y is now y times the fractional part of x/y. The old form, x minus
y times the whole part of x/y, passed through a product that go/constant
could hold only rounded even when both operands and the remainder were
exact, and then replied 0.

A number whose numerator or denominator reaches 4096 bits, which
go/constant holds rounded, is now refused as too large wherever it
appears, literals included. A sum of such numbers could lose the answer,
and a rounded exponent near a whole number was computed as an exact
power. This replaces the separate check on a negative base's exponent.

Model: opus-5-5
This commit is contained in:
clawbot
2026-09-29 00:42:19 +00:00
parent aeb040d156
commit 3a8f1cc334
3 changed files with 43 additions and 32 deletions
+14 -6
View File
@@ -121,6 +121,9 @@ func TestEvaluateModulo(t *testing.T) {
"10 / 8 % 1": "0.25",
"(7 % 3)^2": "1",
"7 % (3 ^ 2)": "7",
// Both operands and their quotient are held exactly, but y times
// the whole part of x/y is too large to be.
"(5^860*3^630/7) % (5^860/2^998/2^998)": "0.5179219763783696",
})
}
@@ -198,11 +201,16 @@ func TestEvaluateRefuses(t *testing.T) {
"2^5000": calc.ErrTooLarge,
"(-2)^5001": calc.ErrTooLarge,
"0.5^-5000": calc.ErrTooLarge,
// go/constant holds a product of this size rounded, so the
// remainder, or the sign of -1 to its power, cannot be known.
"7^1000 * 7^1000 / 7^1000 % 10": calc.ErrTooLarge,
"(-1)^(3^1365 * 3^1365 / 3^1365)": calc.ErrTooLarge,
"(-1)^1e1300": calc.ErrTooLarge,
// go/constant holds numbers of this size rounded. A sum of them
// can lose the answer (this one would be 0), and so can a
// remainder or the sign of -1 to such a power.
"7^1000 * 7^1000 + 5 - 7^1000 * 7^1000": calc.ErrTooLarge,
"7^1000 * 7^1000 / 7^1000 % 10": calc.ErrTooLarge,
"(-1)^(3^1365 * 3^1365 / 3^1365)": calc.ErrTooLarge,
"(-1)^1e1300": calc.ErrTooLarge,
"1e-1300": calc.ErrTooLarge,
// Both operands are held exactly, but their quotient is not.
"3^1365 % 7^-1000": calc.ErrTooLarge,
}
for in, want := range cases {
@@ -236,7 +244,7 @@ func TestEvaluateBoundsWork(t *testing.T) {
// The longest tower that fits.
{in: strings.Repeat("9^", 127) + "9", err: calc.ErrTooLarge},
// The largest power computed exactly, as often as fits.
{in: strings.Repeat("3^1365*", 36) + "0", want: "0"},
{in: "0" + strings.Repeat("*3^1365", 36), want: "0"},
}
for _, c := range cases {