Refuse numbers a double cannot hold; exact powers up to the limit (closes #3)
check / check (push) Successful in 1m4s

A power computed in float64 is refused unless its base and its result
are normal doubles, and so is a result other than zero that is not one:
below about 2.2e-308 a double keeps fewer digits, and at 0 or infinity
none. A literal that go/constant reads as 0 though it is not, such as
1e-999999999, is refused too.

A whole exponent up to 4096 either way is computed exactly and kept
when go/constant holds the result exactly, so 2^-1400 is exact.

ErrTooLarge becomes ErrOutOfRange, and its reply, "That needs a number
too large or too small for me.", is true of both.

Model: opus-5-5
This commit is contained in:
clawbot
2026-09-29 01:23:40 +00:00
parent 3a8f1cc334
commit a1125e59dd
5 changed files with 171 additions and 97 deletions
+18 -14
View File
@@ -166,20 +166,24 @@ container.
`-4`, `(-2)^2` is `4` and `2^-1` is `0.5`. `%` is the remainder and
ranks with `*` and `/`; its result takes the sign of the divisor, as
in Python, so `7 % 3` is `1`, `-7 % 3` is `2` and `7.5 % 2` is `1.5`.
A power with a whole exponent is exact, so `0.1^2` is `0.01`, unless
its numerator and denominator together could pass 4096 bits; that
power, and one with a fractional exponent, is computed as a double, so
`2^0.5` is `1.4142135623730951`. A negative number to a fractional
power is refused, as having no real result. Numbers are read as
decimal, so `010` is ten. Input over 256 bytes is refused and exact
powers are capped, 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>. A result
beyond the range of a double is refused as too large, and so is any
number, even a small one such as `1e-1300` or one inside a longer
expression, whose numerator or denominator reaches 4096 bits:
`go/constant` could hold it only rounded.
A power with a whole exponent is exact, so `0.1^2` is `0.01` and
`2^-1400 * 2^1400` is `1`, unless `go/constant` could hold the result
only rounded; that power, and one with a fractional exponent, is
computed as a double, so `2^0.5` is `1.4142135623730951`. A negative
number to a fractional power is refused, as having no real result.
Numbers are read as decimal, so `010` is ten. Input over 256 bytes is
refused and exact powers are capped, 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` could hold it only rounded (`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`).
- **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