arcade-mcp/toolkits/math/arcade_math/tools/trigonometry.py
Mateo Torres ab735eb442
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.
2025-03-19 13:48:18 -03:00

30 lines
724 B
Python

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(
degrees: Annotated[str, "Angle in degrees as a string"],
) -> Annotated[str, "Angle in radians as a string"]:
"""
Convert an angle from degrees to radians.
"""
# Use Decimal for arbitrary precision
return str(math.radians(Decimal(degrees)))
@tool
def rad_to_deg(
radians: Annotated[str, "Angle in radians as a string"],
) -> Annotated[str, "Angle in degrees as a string"]:
"""
Convert an angle from radians to degrees.
"""
# Use Decimal for arbitrary precision
return str(math.degrees(Decimal(radians)))