fix(tools): calculator reads each written number from its text
The float ast had already rounded each literal, so ceil(1.0000000000000001) gave 1, 1e-400/1e-400 was refused as a division by zero and 1e400-1e400 as out of range. Float literals are now read from the expression text with Decimal (written numbers past 1e4000 are refused unparsed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,9 @@ def test_it_gives_the_exact_value(expression, expected):
|
||||
("10.5 % 0.1", "0"),
|
||||
("2.675*100 // 1", "267"),
|
||||
("0.5^-2", "4"),
|
||||
("ceil(1.0000000000000001)", "2"),
|
||||
("1e-400/1e-400", "1"),
|
||||
("1e400-1e400", "0"),
|
||||
])
|
||||
def test_decimals_are_exact_as_written(expression, expected):
|
||||
assert value_of(run(expression)) == expected
|
||||
@@ -75,7 +78,7 @@ def test_anything_but_arithmetic_is_refused(expression):
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
@pytest.mark.parametrize("expression", ["9**9**9", "10**100000", "(10**300)**300", "1.5**100000", "2**-100000"])
|
||||
@pytest.mark.parametrize("expression", ["9**9**9", "10**100000", "(10**300)**300", "1.5**100000", "2**-100000", "1e99999999", "1e-99999999*2"])
|
||||
def test_a_huge_power_fails_fast_instead_of_hanging(expression):
|
||||
start = time.monotonic()
|
||||
r = run(expression)
|
||||
|
||||
Reference in New Issue
Block a user