Skip to main content

A lightweight and basic maths interpreter

Project description

mathterpreter

A lightweight and basic maths interpreter

Example usage

Basic usage

from mathterpreter import interpret

print(interpret("54-3*(2+1)-3", use_decimals=False))

Step by step

from mathterpreter import Lexer, Parser

lexer = Lexer("54-3*(2+1)-3", use_decimals=False)
tokens = lexer.tokenize()
parser = Parser(tokens)
tree = parser.parse()
result = tree.evaluate()
print(result)

use_decimals determines whether numbers should be handled as decimal.Decimal rather than float for more accurate but slower calculations. Defaults to True

Command line

python3 -m mathterpreter 54-3*(2+1)-3
# or
echo 54-3*(2+1)-3 | python3 -m mathterpreter

Syntax:

Operation Syntax
Addition a+b
Subtraction a-b
Multiplication a*b
Division a/b
Exponentiation a^b
ath root a√b or asqrtb
Standard Form: aE+b (shorthand for a*10^b)

Constants:

Symbol(s) Value
π/pi 3.141592653589793
e 2.718281828459045
All constants are just replaced with their value, wrapped in brackets.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mathterpreter-1.1.2.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

mathterpreter-1.1.2-py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page