Crates.io | equation |
lib.rs | equation |
version | 1.0.0 |
source | src |
created_at | 2023-09-12 07:39:33.277675 |
updated_at | 2023-09-19 19:59:44.651409 |
description | A Rust library for mathematical expression evaluation and simplification |
homepage | |
repository | https://github.com/davidrhyswhite/equation |
max_upload_size | |
id | 970488 |
size | 30,302 |
A Rust library for mathematical expression evaluation and simplification.
%
& exponent **
support;f32
f64
;sin
, cos
& tan
;atan2(y, x)
;steps
parameter to break evaluation steps into a Vec<&str>
;Add the following lines to your Cargo.toml
dependencies:
[dependencies]
equation = "1.0.0"
Evaluate basic arithmetic equations and return a f64
.
use equation::evaluate;
fn main() {
let result = evaluate("(1 + 2) * (1 + 2)"); // Returns Ok(9.0)
match result {
Ok(val) => println!("{}", val),
Err(e) => println!("Error: {:?}", e),
}
}
Basic arithematic
evaluate("(1 + 2) * 1 + 2"); // Returns Ok(5.0)
evaluate("4 * 3"); // Returns Ok(12.0)
evaluate("8 / 2"); // Returns Ok(4.0)
evaluate("16 - 4"); // Returns Ok(12.0)
Negative calculations
Unary operator. Returns the negation of its operand.
evaluate("-4 * 3"); // Returns Ok(-12.0)
evaluate("-8 / 2"); // Returns Ok(-4.0)
evaluate("-(4 + 4)"); // Returns Ok(-8.0)
Exponentation
Calculates the base to the exponent power, base ^ exponent
.
evaluate("2 ^ 8"); // Returns Ok(256.0)
evaluate("2 exp 9"); // Returns Ok(512.0)
Modulus
Returns the integer remainder of dividing the two operands.
evaluate("10 % 2"); // Returns Ok(0.0)
evaluate("10 % 4"); // Returns Ok(2.0)
evaluate("10 mod 3"); // 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);) |
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/).