arcade-mcp/toolkits/math/arcade_math/tools/rational.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

30 lines
850 B
Python

import math
from typing import Annotated
from arcade.sdk import tool
@tool
def gcd(
a: Annotated[str, "First integer as a string"],
b: Annotated[str, "Second integer as a string"],
) -> Annotated[str, "The greatest common divisor of a and b as a string"]:
"""
Calculate the greatest common divisor (GCD) of two integers.
"""
return str(math.gcd(int(a), int(b)))
@tool
def lcm(
a: Annotated[str, "First integer as a string"],
b: Annotated[str, "Second integer as a string"],
) -> Annotated[str, "The least common multiple of a and b as a string"]:
"""
Calculate the least common multiple (LCM) of two integers.
Returns "0" if either integer is 0.
"""
a_int, b_int = int(a), int(b)
if a_int == 0 or b_int == 0:
return "0"
return str(abs(a_int * b_int) // math.gcd(a_int, b_int))