Refuse numbers a double cannot hold; exact powers up to the limit (closes #3)
check / check (push) Successful in 1m4s
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:
+2
-2
@@ -221,8 +221,8 @@ func Reply(text string) string {
|
||||
calc.MaxInputLength)
|
||||
case errors.Is(err, calc.ErrDivisionByZero):
|
||||
return "I cannot divide by zero."
|
||||
case errors.Is(err, calc.ErrTooLarge):
|
||||
return "The result is too large for me."
|
||||
case errors.Is(err, calc.ErrOutOfRange):
|
||||
return "That needs a number too large or too small for me."
|
||||
case errors.Is(err, calc.ErrNoRealResult):
|
||||
return "A negative number to a fractional power has no real result."
|
||||
default:
|
||||
|
||||
@@ -27,7 +27,8 @@ func TestReply(t *testing.T) {
|
||||
for in, want := range map[string]string{
|
||||
"hello": "I only understand arithmetic",
|
||||
"1 / 0": "I cannot divide by zero.",
|
||||
"1e400": "The result is too large for me.",
|
||||
"1e400": "That needs a number too large or too small for me.",
|
||||
"1e-1300": "That needs a number too large or too small for me.",
|
||||
"(-8)^0.5": "A negative number to a fractional power has no real",
|
||||
strings.Repeat("1+", calc.MaxInputLength) + "1": "That is too long for me",
|
||||
} {
|
||||
|
||||
Reference in New Issue
Block a user