8 releases (1 stable)

1.0.0 Jul 14, 2021
0.9.7 Jul 2, 2021
0.9.4 Jun 30, 2021
0.9.3 May 22, 2019
0.9.0 Apr 29, 2019

#1058 in Algorithms

Download history 38/week @ 2024-07-28 125/week @ 2024-08-11 345/week @ 2024-08-18 338/week @ 2024-08-25 465/week @ 2024-09-01 441/week @ 2024-09-08 414/week @ 2024-09-15 455/week @ 2024-09-22 435/week @ 2024-09-29 328/week @ 2024-10-06 439/week @ 2024-10-13 444/week @ 2024-10-20 650/week @ 2024-10-27 834/week @ 2024-11-03 754/week @ 2024-11-10

2,744 downloads per month
Used in 2 crates

MIT license

135KB
3K SLoC

What is it

Mathematical expression evaluation library with big integers, floats, common fractions, and complex numbers support. The library is used by the project RionaCalc

Features

  • Automatic selection of more appropriate argument type for a function: e.g, sqrt(-4) converts float number -4 into complex one -4+0i and then calculates the result 0+2i. The same is true for calculating logarithm for negative float numbers, and acos and asin for argument greater than 1.0
  • Automatic adding multiplication sign where it is omitted: e.g, (1+2)(2+9) is calculated as (1+2)*(2+9)
  • Functions with a single-value argument do not require to enclose its argument into brackets: e.g, sin cos 2 is calculated as sin(cos(2))
  • The final closing brackets can be omitted: e.g, (1+2)*(2+9 is the same as (1+2)*(2+9)
  • Trigonometric functions work with radians and degrees. Bare numbers are treated as radians, degrees requires one or three suffixes. Two degrees formats: 20d30m50s or 20°30'50". Minutes and seconds can be omitted, in this case degrees can be float number like 30.25d. So, sin(pi/2) == sin(90°)
  • Every number can include group separator _ for readability - it is very useful when using big integers. 3_000.90_23 == 3000.9023
  • Both . and , are treated as decimal separators
  • Function argument separator is ;. If a function receives more arguments than it requires, the trailing arguments are dropped: e.g, sqrt(11;12;13) is the same as sqrt(11)
  • Regular fractions use \ to separate its parts. They can be written with integer part or only with numerator and denominator, e.g 1\1\10 == 11\10
  • Two complex numbers formats: with marker at the end or in the middle. E.g, 1+2i == 1+i2. In addition, j can be used instead of i - but the calculator outputs always with i
  • Hexadecimal(starts with 0x), octal(starts with 0o), and binary(starts with 0b) numbers
  • Character % can be either a modulo or a percentage operator. It depends on the character position: if % is right before the expression end or before closing bracket or before another operator and previous operator is one of +, -, *, or /, the character is considered a percentage operator

Dependencies

~3.5MB
~73K SLoC