bexeval
Bexeval is a Rust crate for evaluating mathematical expressions with integer numeric types written as strings.
Features
- Parse and evaluate simple mathematical expressions.
- Basic arithmetic operations:
+,-,*,/,%,&,|,^,<<,>>,!(operator not) - Comparison operators (Return 1 if true, 0 if false):
==,!=,<,<=,>,>= - Parentheses for expression grouping
- Common mathematical functions (possibility of adding more functions in the future):
pow,count_ones,abs...
- Basic arithmetic operations:
- Can select primitive integer type as the numeric value type:
u8,u16,u32,u64,usize,i8,i16,i32,i64,isize - Support for variables.
- Minimal dependencies (only
num-traits).
Usage
Add the bexeval crate to your Cargo.toml file:
[]
= "<version>"
Then, in your Rust code:
use *;
let parser = new;
assert_eq!;
assert_eq!;
assert_eq!;
The context argument stores information about the variable in array of tuples(&str, T).
Wrapping operations are used for operations that may overflow. (wrapping_add, wrapping_mul...)
Be careful of overflow.
Dividing by zero causes panic.
You can assign numerical values to variables and evaluate them using Context.
# use *;
#
let mut ctx = new;
ctx.assign;
assert_eq!;
ctx.assign_stmt.unwrap;
assert_eq!;
// wrapping operation
assert_eq!;
Available function
powabsabs_diff(Available even with rustc versions below 1.60)count_onescount_zerosleading_zerostrailing_zerosrotate_leftrotate_right
API Documentation
Detailed API documentation can be found here.
License
This project is licensed under the MIT license.