Equation
A Rust library for mathematical expression evaluation and simplification.
TODO
- Rewrite pest parsing as PrattParser;
- Modulo
%& exponent**support; - Unary minus operator support;
- Support fractions as
f32f64; - Support basic triggernomic ratio functions sine, cosine & tangent as
sin,cos&tan; - Support functions with additional arguments,
atan2(y, x); - Support evaluate
stepsparameter to break evaluation steps into aVec<&str>; - Support simplification & evaluation of algebraic expressions;
- Support for vectors and basic vector arithmetic & operations;
Getting started
Add the following lines to your Cargo.toml dependencies:
[]
= "1.0.0"
Examples
Evaluate basic arithmetic equations and return a f64.
use evaluate;
Support
Basic arithematic
evaluate; // Returns Ok(5.0)
evaluate; // Returns Ok(12.0)
evaluate; // Returns Ok(4.0)
evaluate; // Returns Ok(12.0)
Negative calculations
Unary operator. Returns the negation of its operand.
evaluate; // Returns Ok(-12.0)
evaluate; // Returns Ok(-4.0)
evaluate; // Returns Ok(-8.0)
Exponentation
Calculates the base to the exponent power, base ^ exponent.
evaluate; // Returns Ok(256.0)
evaluate; // Returns Ok(512.0)
Modulus
Returns the integer remainder of dividing the two operands.
evaluate; // Returns Ok(0.0)
evaluate; // Returns Ok(2.0)
evaluate; // Returns Ok(1.0)
Triggernomic functions
| Function | Description | Example | Result |
|---|---|---|---|
| sin | Sine of the input | evaluate("sin(10.0)); |
Ok(-0.5440211108893698) |
| cos | Cosine of the input | evaluate("cos(10.0)); |
Ok(-0.8390715290764524) |
| tan | Tangent of the input | evaluate("tan(10.0)); |
Ok(0.6483608274590867) |
| asin | Inverse sine of the input | evaluate("asin(0.5)); |
Ok(0.5235987755982988);) |
| acos | Inverse cosine of the input | evaluate("acos(0.5)); |
Ok(1.0471975511965976);) |
| atan | Inverse tangent of the input | evaluate("atan(10.0)); |
Ok(1.4711276743037345);) |
| sinh | Hyperbolic sine of the input | evaluate("sinh(10.0)); |
Ok(11013.232874703393);) |
| cosh | Hyperbolic cosine of the input | evaluate("cosh(10.0)); |
Ok(11013.232920103323);) |
| tanh | Hyperbolic tangent of the input | evaluate("tanh(10.0)); |
Ok(0.9999999958776927);) |
| asinh | Inverse hyperbolic sine of the input | evaluate("asinh(10.0)); |
Ok(2.99822295029797);) |
| acosh | Inverse hyperbolic cosine of the input | evaluate("acosh(10.0)); |
Ok(2.993222846126381);) |
| atanh | Inverse hyperbolic tangent of the input | evaluate("atanh(10.0)); |
Ok(0.5493061443340549);) |
License
Licensed under MIT license (LICENSE-MIT | https://opensource.org/licenses/MIT) or under the Apache 2.0 (LICENSE-APACHE | https://opensource.org/license/apache-2-0/).