simple-math
is a badly-named messy piece of crap that doesn't even support compiling to AST before executing.
Alternatives:
- For a binary, check out math-test-haskell. Even though Haskell is probably slower, for this particular project I don't really care.
- For a library, check out calc, maintained by the Redox team and used within the ion shell.
I was bored, so I made some simple math parser and calculator.
- Arbitrary-length ("big") numbers. (Thanks to library "num")
- Binary/Octal/Hexadecimal numbers
- Bitwise operators
- Factorial
- Function system
- Negative numbers
- Non-whole numbers. (Thanks to library "bigdecimal-rs")
- Orders of operations
- Actually implement some functions
EDIT: Ugh, I can't even make a single project without @tbodt knowing a better solution :P
This time he told me about recursive parsers :O
So yeah, huge thanks to him for being such an awesome person!
After a lot of development, this actually turned out to be a pretty cool project.
Let's compare it to GNU bc
!
simple-math
cons:
- New technology. Therefore it's currently less stable.
- Power using
pow(x, y)
, notx^y
. This is due to the^
operator doing something else. bc
is more powerful.- Probably some more things I don't know about.
simple-math
pros:
- Supports factorial built-in.
- No need to struggle with
scale=
. - Auto-inserts times where needed (e.g.
2(2 + 2)
is8
). - Supports bitwise operators and bitshifting.