Skip to content

Commit 5b828b9

Browse files
committed
Support more arithmetic operators
1 parent 9380db6 commit 5b828b9

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/mcp_server_calculator/calculator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def eval_expr(node):
2626
return -eval_expr(node.operand)
2727
raise ValueError(f"Unsupported operation: {ast.dump(node)}")
2828

29+
expression = expression.replace('^', '**').replace('×', '*').replace('÷', '/')
2930
parsed_expr = ast.parse(expression, mode='eval')
3031
result = eval_expr(parsed_expr.body)
3132
return str(result)

tests/test_calculator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ def test_subtraction(self):
1010

1111
def test_multiplication(self):
1212
self.assertEqual(evaluate("2 * 3"), "6")
13+
self.assertEqual(evaluate("2 × 3"), "6")
1314

1415
def test_division(self):
1516
self.assertEqual(evaluate("8 / 2"), "4.0")
17+
self.assertEqual(evaluate("8 ÷ 2"), "4.0")
1618

1719
def test_floor_division(self):
1820
self.assertEqual(evaluate("7 // 2"), "3")
@@ -22,6 +24,7 @@ def test_modulus(self):
2224

2325
def test_power(self):
2426
self.assertEqual(evaluate("2 ** 3"), "8")
27+
self.assertEqual(evaluate("2 ^ 3"), "8")
2528

2629
def test_unary_minus(self):
2730
self.assertEqual(evaluate("-5"), "-5")

0 commit comments

Comments
 (0)