increased precision of decimal-based math tools to 100 digits (#315)

Some edge cases of a benchmark were failing due to low precision,
increased the precision to 100 digits.
This commit is contained in:
Mateo Torres 2025-03-19 13:48:18 -03:00 committed by GitHub
parent 0baeb0f219
commit ab735eb442
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 62 additions and 12 deletions

View file

@ -1,8 +1,11 @@
import decimal
from decimal import Decimal
from typing import Annotated
from arcade.sdk import tool
decimal.getcontext().prec = 100
@tool
def add(

View file

@ -1,9 +1,12 @@
import decimal
import math
from decimal import Decimal
from typing import Annotated
from arcade.sdk import tool
decimal.getcontext().prec = 100
@tool
def log(

View file

@ -1,9 +1,12 @@
import decimal
import math
from decimal import Decimal
from typing import Annotated
from arcade.sdk import tool
decimal.getcontext().prec = 100
@tool
def abs_val(

View file

@ -1,9 +1,12 @@
import decimal
import math
from decimal import Decimal
from typing import Annotated
from arcade.sdk import tool
decimal.getcontext().prec = 100
@tool
def ceil(

View file

@ -1,9 +1,12 @@
import decimal
from decimal import Decimal
from statistics import median as stats_median
from typing import Annotated
from arcade.sdk import tool
decimal.getcontext().prec = 100
@tool
def avg(

View file

@ -1,9 +1,12 @@
import decimal
import math
from decimal import Decimal
from typing import Annotated
from arcade.sdk import tool
decimal.getcontext().prec = 100
@tool
def deg_to_rad(

View file

@ -62,13 +62,13 @@ def test_subtract(a, b, expected):
(
"12345678901234567890",
"18000000162000001474380013420000",
"2.222222222222222222222222223E+50",
"222222222222222222222222222261233060226101083800000",
),
# Big floats
(
"12345678901234567890.120",
"12345678901234567890.120",
"1.524157875323883675048681628E+38",
"152415787532388367504868162811315348393.614400",
),
],
)
@ -81,7 +81,12 @@ def test_multiply(a, b, expected):
[
("-1", "2", "-0.5"),
("-10", "1", "-10"),
("0.5", "10.9", "0.04587155963302752293577981651"),
(
"0.5",
"10.9",
"0.0458715596330275229357798165137614678899082568807339"
"4495412844036697247706422018348623853211009174312",
),
# Big ints
("152407406035740740602050", "12345678901234567890", "12345"),
# Big floats

View file

@ -20,10 +20,19 @@ def test_log():
def test_power():
assert power("-8", "2") == "64"
assert power("0", "10") == "0"
assert power("2", "0.5") == "1.414213562373095048801688724"
assert (
power("2", "0.5") == "1.41421356237309504880168872420969807856"
"9671875376948073176679737990732478462107038850387534327641573"
)
assert power("2", "3") == "8"
assert power("2.", "-0.5") == "0.7071067811865475244008443621"
assert power("2.1234", "0.6") == "1.571155202490495156807227175"
assert (
power("2.", "-0.5") == "0.707106781186547524400844362104849039"
"2848359376884740365883398689953662392310535194251937671638207864"
)
assert (
power("2.1234", "0.6") == "1.571155202490495156807227174573016145"
"282682479346448636509576776014844055570115193494685328114403375"
)
assert power("2.1234", "1") == "2.1234"
assert power("2.1234", "3") == "9.574044440904"
assert power("8", "-2") == "0.015625"

View file

@ -41,16 +41,34 @@ def test_sqrt():
assert sqrt("1") == "1"
assert sqrt("0") == "0"
assert sqrt("-0") == "-0"
assert sqrt("23") == "4.795831523312719541597438064"
assert sqrt("24") == "4.898979485566356196394568149"
assert sqrt("10") == "3.162277660168379331998893544"
assert (
sqrt("23") == "4.79583152331271954159743806416269391999670704190"
"4129346485309114448257235907464082492191446436918861"
)
assert (
sqrt("24") == "4.89897948556635619639456814941178278393189496131"
"3340256865385134501920754914630053079718866209280470"
)
assert (
sqrt("10") == "3.16227766016837933199889354443271853371955513932"
"5216826857504852792594438639238221344248108379300295"
)
assert sqrt("0.0") == "0.0"
assert sqrt("0.0000") == "0.00"
assert sqrt("-0.0") == "-0.0"
assert sqrt("1.0") == "1.0"
assert sqrt("3.14") == "1.772004514666935040199112510"
assert sqrt("0.4") == "0.6324555320336758663997787089"
assert sqrt("10.0") == "3.162277660168379331998893544"
assert (
sqrt("3.14") == "1.772004514666935040199112509753631525073608516"
"162942966817771970290992972348902551472561151153909188"
)
assert (
sqrt("0.4") == "0.6324555320336758663997787088865437067439110278"
"650433653715009705585188877278476442688496216758600590"
)
assert (
sqrt("10.0") == "3.162277660168379331998893544432718533719555139"
"325216826857504852792594438639238221344248108379300295"
)
with pytest.raises(ToolExecutionError):
sqrt("-1")
with pytest.raises(ToolExecutionError):