New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mathterpreter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mathterpreter

A lightweight and basic maths interpreter

  • 1.1.2
  • PyPI
  • Socket score

Maintainers
1

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:

OperationSyntax
Additiona+b
Subtractiona-b
Multiplicationa*b
Divisiona/b
Exponentiationa^b
ath roota√b or asqrtb
Standard Form:aE+b (shorthand for a*10^b)

Constants:

Symbol(s)Value
π/pi3.141592653589793
e2.718281828459045
All constants are just replaced with their value, wrapped in brackets.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc