added speed of light global
This commit is contained in:
parent
f7d6ee9d7e
commit
6b36e8340d
3 changed files with 4 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
pub const EULER: f64 = 2.718281828459045;
|
pub const EULER: f64 = 2.718281828459045;
|
||||||
pub const GOLDEN_RATIO: f64 = 1.618033988749895;
|
pub const GOLDEN_RATIO: f64 = 1.618033988749895;
|
||||||
|
pub const LIGHT_SPEED: f64 = 299792458f64;
|
||||||
pub const PI: f64 = 3.141592653589793;
|
pub const PI: f64 = 3.141592653589793;
|
||||||
pub const ROOT_TWO: f64 = 1.414213562373095;
|
pub const ROOT_TWO: f64 = 1.414213562373095;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub fn fix(arg: &Value) -> EvalResult {
|
||||||
|
|
||||||
let count = args.len();
|
let count = args.len();
|
||||||
if count != 2 {
|
if count != 2 {
|
||||||
return Err(EvalexprError::WrongFunctionArgumentAmount { expected: 2, actual: count });
|
return Err(EvalexprError::WrongFunctionArgumentAmount { expected: 2..=2, actual: count });
|
||||||
}
|
}
|
||||||
|
|
||||||
let float = args[0].as_float()?;
|
let float = args[0].as_float()?;
|
||||||
|
@ -63,7 +63,7 @@ pub fn logarithm(arg: &Value) -> EvalResult {
|
||||||
output = value.log(base).into();
|
output = value.log(base).into();
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
return Err(EvalexprError::WrongFunctionArgumentAmount { expected: 2, actual: count });
|
return Err(EvalexprError::WrongFunctionArgumentAmount { expected: 2..=2, actual: count });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(output);
|
return Ok(output);
|
||||||
|
|
|
@ -31,6 +31,7 @@ fn main() {
|
||||||
// build eval context
|
// build eval context
|
||||||
let mut context = context_map! {
|
let mut context = context_map! {
|
||||||
// globals
|
// globals
|
||||||
|
"c" => global::LIGHT_SPEED,
|
||||||
"e" => global::EULER,
|
"e" => global::EULER,
|
||||||
"phi" => global::GOLDEN_RATIO,
|
"phi" => global::GOLDEN_RATIO,
|
||||||
"pi" => global::PI,
|
"pi" => global::PI,
|
||||||
|
|
Loading…
Reference in a new issue