Struct xxcalc::polynomial_calculator::PolynomialCalculator [] [src]

pub struct PolynomialCalculator;

PolynomialCalculator is a calculator using a PolynomialParser and a PolynomialEvaluator to provide multiple default operations.

This calculator supports addition +, subtraction -, multiplication *, division / and exponentiation ^ operators, log(number, base), log10(number) and bind(polynomial, double) functions, x, inf, nan symbols and pi and e constants.

While usage of the calculator is the easiest way of embedding computation engine into your program, please note that a Tokenizer, PolynomialParser and PolynomialEvaluator is created with each call, which requires reallocation of memory.

Examples

assert_eq!(PolynomialCalculator.process("2+2"), Ok(Polynomial::constant(4.0)));
assert_eq!(PolynomialCalculator.process("(2+2)*-2"), Ok(Polynomial::constant(-8.0)));
assert_eq!(String::from(PolynomialCalculator.process("(x+1)*(-0.13x^18-x^7)").unwrap()), "-0.13x^19-0.13x^18-x^8-x^7");
assert_eq!(PolynomialCalculator.process("bind(pi*x^2, 10)"), Ok(Polynomial::constant(PI * 10.0 * 10.0)));Run

Trait Implementations

impl Calculator<TokenizerPolynomialParserPolynomialEvaluator> for PolynomialCalculator
[src]

Takes string and evaluates it into a Polynomial. Read more