[−][src]Crate cpc
calculation + conversion
cpc parses and evaluates strings of math, with support for units and conversion. 128-bit decimal floating points are used for high accuracy.
cpc lets you mix units, so for example 1 km - 1m results in Number { value: 999, unit: Meter }.
Check out the list of supported units
Example usage
use cpc::{eval}; use cpc::units::Unit; match eval("3m + 1cm", true, Unit::Celsius, false) { Ok(answer) => { // answer: Number { value: 301, unit: Unit::Centimeter } println!("Evaluated value: {} {:?}", answer.value, answer.unit) }, Err(e) => { println!("{}", e) } }
Modules
evaluator | |
lexer | Turns a string into a |
parser | Turns a |
units | Units, and functions you can use with them |
Structs
Number | A number with a |
Enums
Constant | |
FunctionIdentifier | |
LexerKeyword | A temporary enum used by the |
NamedNumber | A named number like |
Operator | Math operators like |
TextOperator | |
Token | |
UnaryOperator |
Functions
eval | Evaluates a string into a resulting |
Type Definitions
TokenVector | A vector of |