azrideus-mathparse 0.2.18__tar.gz → 0.2.19__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/PKG-INFO +1 -1
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/azrideus_mathparse.egg-info/PKG-INFO +1 -1
- azrideus_mathparse-0.2.19/mathparse/__init__.py +12 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/evaluator.py +6 -1
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/mathparse.py +7 -2
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/pyproject.toml +1 -4
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_binary_operations.py +31 -0
- azrideus_mathparse-0.2.18/mathparse/__init__.py +0 -5
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/LICENSE +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/README.md +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/azrideus_mathparse.egg-info/SOURCES.txt +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/azrideus_mathparse.egg-info/dependency_links.txt +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/azrideus_mathparse.egg-info/requires.txt +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/azrideus_mathparse.egg-info/top_level.txt +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/exceptions.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/extraction.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/limits.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/mathwords.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/patterns.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/postfix.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/tokenizer.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/tokens.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/mathparse/word_tokens.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/setup.cfg +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_bitshift_operations.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_bitwise_operations.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_comparison_operations.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_complex_statements.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_hex_numbers.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_language_support.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_limits.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_prefix_unary_operations.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_replace_word_tokens.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_simplified_chinese.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_unary_operations.py +0 -0
- {azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: azrideus-mathparse
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.19
|
|
4
4
|
Summary: A fork of mathparse (https://github.com/gunthercox/mathparse) for my own usage; a library for solving mathematical equations contained in strings
|
|
5
5
|
Author: Gunther Cox
|
|
6
6
|
License-Expression: MIT
|
{azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/azrideus_mathparse.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: azrideus-mathparse
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.19
|
|
4
4
|
Summary: A fork of mathparse (https://github.com/gunthercox/mathparse) for my own usage; a library for solving mathematical equations contained in strings
|
|
5
5
|
Author: Gunther Cox
|
|
6
6
|
License-Expression: MIT
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mathparse is a library for solving mathematical equations contained in strings
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
6
|
+
|
|
7
|
+
# The version is set in pyproject.toml
|
|
8
|
+
try:
|
|
9
|
+
__version__ = version("azrideus-mathparse")
|
|
10
|
+
except PackageNotFoundError:
|
|
11
|
+
# Running from a source checkout that is not installed
|
|
12
|
+
__version__ = "unknown"
|
|
@@ -112,7 +112,12 @@ def evaluate_postfix(tokens: list) -> Union[int, float, str, Decimal]:
|
|
|
112
112
|
and abs(base) > 1
|
|
113
113
|
):
|
|
114
114
|
check_integer_digits(exponent * math.log10(abs(base)), token)
|
|
115
|
-
|
|
115
|
+
# A negative number to a fractional power has no real result
|
|
116
|
+
# Example: (-8) ^ 0.5
|
|
117
|
+
if base < 0 and exponent != int(exponent):
|
|
118
|
+
total = "undefined"
|
|
119
|
+
else:
|
|
120
|
+
total = base**exponent
|
|
116
121
|
elif token == "/":
|
|
117
122
|
# Convert tokens such as constants (e.g. "pi") to numbers
|
|
118
123
|
# before passing them to Decimal
|
|
@@ -15,7 +15,7 @@ the following modules, and everything they define can be imported from here:
|
|
|
15
15
|
- extraction: finding an expression inside a sentence
|
|
16
16
|
"""
|
|
17
17
|
|
|
18
|
-
from decimal import Decimal, DecimalException
|
|
18
|
+
from decimal import Decimal, DecimalException, Overflow
|
|
19
19
|
from typing import Union
|
|
20
20
|
import sys
|
|
21
21
|
import types
|
|
@@ -166,9 +166,14 @@ def parse(
|
|
|
166
166
|
|
|
167
167
|
try:
|
|
168
168
|
return evaluate_postfix(postfix)
|
|
169
|
-
except (OverflowError,
|
|
169
|
+
except (OverflowError, Overflow) as error:
|
|
170
170
|
# Float and Decimal operations raise these when a result is too large
|
|
171
171
|
# (e.g. 10.0 ^ 400 or exp(1000))
|
|
172
172
|
raise ExpressionTooLargeException(
|
|
173
173
|
"The result is too large to compute: {}".format(error)
|
|
174
174
|
) from error
|
|
175
|
+
except DecimalException as error:
|
|
176
|
+
# Other Decimal errors, such as 0.0 ^ 0 (an invalid operation)
|
|
177
|
+
raise PostfixTokenEvaluationException(
|
|
178
|
+
"The expression can not be evaluated: {}".format(error)
|
|
179
|
+
) from error
|
|
@@ -7,11 +7,9 @@ packages=[
|
|
|
7
7
|
"mathparse",
|
|
8
8
|
]
|
|
9
9
|
|
|
10
|
-
[tool.setuptools.dynamic]
|
|
11
|
-
version = {attr = "mathparse.__version__"}
|
|
12
|
-
|
|
13
10
|
[project]
|
|
14
11
|
name = "azrideus-mathparse"
|
|
12
|
+
version = "0.2.19"
|
|
15
13
|
requires-python = ">=3.10,<3.15"
|
|
16
14
|
urls = { Documentation = "https://mathparse.chatterbot.us", Repository = "https://github.com/gunthercox/mathparse", Changelog = "https://github.com/gunthercox/mathparse/releases" }
|
|
17
15
|
authors = [
|
|
@@ -20,7 +18,6 @@ authors = [
|
|
|
20
18
|
license = "MIT"
|
|
21
19
|
description = "A fork of mathparse (https://github.com/gunthercox/mathparse) for my own usage; a library for solving mathematical equations contained in strings"
|
|
22
20
|
readme = "README.md"
|
|
23
|
-
dynamic = ["version"]
|
|
24
21
|
keywords = [
|
|
25
22
|
"mathparse",
|
|
26
23
|
"mathematics",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from decimal import Decimal
|
|
2
2
|
from unittest import TestCase
|
|
3
3
|
from mathparse import mathparse, mathwords
|
|
4
|
+
from mathparse.exceptions import PostfixTokenEvaluationException
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
class PositiveIntegerTestCase(TestCase):
|
|
@@ -371,3 +372,33 @@ class ExactFloatArithmeticTestCase(TestCase):
|
|
|
371
372
|
|
|
372
373
|
self.assertEqual(result, 18)
|
|
373
374
|
self.assertIsInstance(result, int)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
class NegativeBasePowerTestCase(TestCase):
|
|
378
|
+
"""
|
|
379
|
+
A negative number to a fractional power has no real result.
|
|
380
|
+
"""
|
|
381
|
+
|
|
382
|
+
def test_negative_base_decimal_exponent(self):
|
|
383
|
+
self.assertEqual(mathparse.parse("(-8) ^ 0.5"), "undefined")
|
|
384
|
+
|
|
385
|
+
def test_negative_base_division_exponent(self):
|
|
386
|
+
self.assertEqual(mathparse.parse("(-8) ^ (1 / 2)"), "undefined")
|
|
387
|
+
|
|
388
|
+
def test_negative_decimal_base_fractional_exponent(self):
|
|
389
|
+
self.assertEqual(mathparse.parse("(-8.5) ^ 0.5"), "undefined")
|
|
390
|
+
|
|
391
|
+
def test_negative_base_integer_exponent(self):
|
|
392
|
+
self.assertEqual(mathparse.parse("(-8) ^ 2"), 64)
|
|
393
|
+
|
|
394
|
+
def test_negative_base_whole_decimal_exponent(self):
|
|
395
|
+
self.assertEqual(mathparse.parse("(-8) ^ 2.0"), 64)
|
|
396
|
+
|
|
397
|
+
def test_invalid_decimal_operation_is_not_too_large(self):
|
|
398
|
+
# Decimal 0 ^ 0 is an invalid operation, which is not an overflow
|
|
399
|
+
with self.assertRaises(PostfixTokenEvaluationException) as context:
|
|
400
|
+
mathparse.parse("0.0 ^ 0")
|
|
401
|
+
|
|
402
|
+
self.assertNotIsInstance(
|
|
403
|
+
context.exception, mathparse.ExpressionTooLargeException
|
|
404
|
+
)
|
|
File without changes
|
|
File without changes
|
{azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/azrideus_mathparse.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/azrideus_mathparse.egg-info/requires.txt
RENAMED
|
File without changes
|
{azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/azrideus_mathparse.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{azrideus_mathparse-0.2.18 → azrideus_mathparse-0.2.19}/tests/test_prefix_unary_operations.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|