From 6b36e8340d1e04702b1b83dcb0e94f5fab7f3e0a Mon Sep 17 00:00:00 2001 From: Valerie Date: Wed, 28 Feb 2024 20:59:52 -0500 Subject: [PATCH] added speed of light global --- src/global.rs | 1 + src/helper.rs | 4 ++-- src/main.rs | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/global.rs b/src/global.rs index 3dddcd3..025b0f4 100644 --- a/src/global.rs +++ b/src/global.rs @@ -1,6 +1,7 @@ pub const EULER: f64 = 2.718281828459045; pub const GOLDEN_RATIO: f64 = 1.618033988749895; +pub const LIGHT_SPEED: f64 = 299792458f64; pub const PI: f64 = 3.141592653589793; pub const ROOT_TWO: f64 = 1.414213562373095; diff --git a/src/helper.rs b/src/helper.rs index 02c57de..221147a 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -15,7 +15,7 @@ pub fn fix(arg: &Value) -> EvalResult { let count = args.len(); 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()?; @@ -63,7 +63,7 @@ pub fn logarithm(arg: &Value) -> EvalResult { 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); diff --git a/src/main.rs b/src/main.rs index c0a5395..ed5bc0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,7 @@ fn main() { // build eval context let mut context = context_map! { // globals + "c" => global::LIGHT_SPEED, "e" => global::EULER, "phi" => global::GOLDEN_RATIO, "pi" => global::PI,