Write exact results past the range of a double (closes #16)
check / check (push) Successful in 1m43s

An exact result outside the normal range of a double, such as 2^1200,
10^400 or 2^-1200, was refused because format wrote every result
through float64. Such a result is now written from its exact value,
rounded to 17 significant digits with trailing zeros dropped, through a
big.Float precise enough to round as the exact value would. Results
inside the range are written as before, and a power computed in float64
must still be a normal double. The tests check the written text of these
results, the refusals just past the 4096-bit limit, and the time taken
to write the largest and smallest numbers under it.

Model: opus-5-5
This commit is contained in:
2026-09-29 06:18:19 +00:00
parent f53b666119
commit c4e4041cd9
5 changed files with 90 additions and 35 deletions
+14 -10
View File
@@ -335,16 +335,20 @@ container.
refused, exact powers are capped, and every number is held as a
fraction, whole numbers too, under the 4096-bit limit below, so a
message cannot make the bot do unbounded work. Whole numbers below
10<sup>21</sup> are written exactly; other results in the shortest
form that reads back as the same double, in exponent notation from
10<sup>21</sup> up and below 10<sup>-6</sup>. Refused as too large or
too small: any number whose numerator or denominator reaches 4096
bits, wherever it appears, as `go/constant` rounds a fraction that
grows that large (`1e-1300 + 1`); a power computed as a double whose
base or result is outside the normal range of a double, about 2.2e-308
to 1.8e308 in magnitude, where a double keeps all its digits
(`1e-400^0.5`); and a result other than zero outside that range, as it
is written through a double (`1e400`, `2^-1400`).
10<sup>21</sup> are written exactly. Other results inside the normal
range of a double, about 2.2e-308 to 1.8e308 in magnitude, where a
double keeps all its digits, are written in the shortest form that
reads back as the same double, in exponent notation from
10<sup>21</sup> up and below 10<sup>-6</sup>. Results outside that
range are written from their exact value in exponent notation, rounded
to 17 significant digits, the most the shortest form of a double
takes, with trailing zeros dropped: `2^1200` is
`1.7218479456385751e+361`, `10^400` is `1e+400` and `2^-1074` is
`4.9406564584124654e-324`. Refused as too large or too small: any
number whose numerator or denominator reaches 4096 bits, wherever it
appears, as `go/constant` rounds a fraction that grows that large
(`2^4095`, `1e-1300 + 1`); and a power computed as a double whose base
or result is outside the normal range of a double (`1e-400^0.5`).
- **Failure is an exit.** If the chat client exits or the connection to
it drops, the bot exits with an error and the container's restart
policy starts both again. `SIGTERM` stops the bot, which stops the