arcade-mcp/toolkits/math/arcade_math/tools/exponents.py
Mateo Torres f04087b389
Math tools expanded (#293)
Migrated all interfaces to get and return strings.

Added tests and evals for all functions (except the random generation)
Math functions are now organized into different math categories

---------

Co-authored-by: Nate Barbettini <nate@arcade-ai.com>
2025-03-14 09:47:04 -03:00

29 lines
864 B
Python

import math
from decimal import Decimal
from typing import Annotated
from arcade.sdk import tool
@tool
def log(
a: Annotated[str, "The number to take the logarithm of as a string"],
base: Annotated[str, "The logarithmic base as a string"],
) -> Annotated[str, "The logarithm of the number with the specified base as a string"]:
"""
Calculate the logarithm of a number with a given base
"""
# Use Decimal for arbitrary precision
return str(math.log(Decimal(a), Decimal(base)))
@tool
def power(
a: Annotated[str, "The base number as a string"],
b: Annotated[str, "The exponent as a string"],
) -> Annotated[str, "The result of raising a to the power of b as a string"]:
"""
Calculate one number raised to the power of another
"""
# Use Decimal for arbitrary precision
return str(Decimal(a) ** Decimal(b))