Skip to content

Commit b30a51f

Browse files
authored
Merge pull request #39 from gunthercox/pi
Add π constant
2 parents 1af30b3 + 5195563 commit b30a51f

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

mathparse/mathwords.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@
786786

787787
CONSTANTS = {
788788
'pi': 3.141693,
789+
'π': 3.141693,
789790
'e': 2.718281
790791
}
791792

tests/test_complex_statements.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,17 @@ def test_stopwords_contained_within_expressions(self):
6464
stopwords={'the', 'of'}
6565
)
6666
self.assertEqual(result, 2)
67+
68+
def test_unicode_pi_symbol(self):
69+
"""
70+
Test using the unicode π symbol as a constant.
71+
"""
72+
result = mathparse.parse('2 * π')
73+
self.assertAlmostEqual(result, 2 * 3.141693, places=5)
74+
75+
def test_unicode_pi_in_expression(self):
76+
"""
77+
Test using the unicode π symbol in a complex expression.
78+
"""
79+
result = mathparse.parse('π + 1')
80+
self.assertAlmostEqual(result, 3.141693 + 1, places=5)

tests/test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def test_is_not_float(self):
2020
def test_is_constant(self):
2121
self.assertTrue(mathparse.is_constant('pi'))
2222

23+
def test_is_constant_unicode_pi(self):
24+
self.assertTrue(mathparse.is_constant('π'))
25+
2326
def test_is_not_constant(self):
2427
self.assertFalse(mathparse.is_constant('+'))
2528

0 commit comments

Comments
 (0)