From b27bf74c5f5daf4bbe20416b8a7b521c7a4eacc5 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Fri, 29 Mar 2019 21:54:13 +0530 Subject: add inverse trignometric functions, remainder operator --- src/lex/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/lex') diff --git a/src/lex/mod.rs b/src/lex/mod.rs index 39538ca..51f124c 100644 --- a/src/lex/mod.rs +++ b/src/lex/mod.rs @@ -94,7 +94,13 @@ fn get_functions() -> HashMap<&'static str, Token> { ("rad", Function::token_from_fn("rad".into(), |x| x.to_radians())), ("deg", Function::token_from_fn("deg".into(), |x| x.to_degrees())), ("abs", Function::token_from_fn("abs".into(), |x| x.abs())), - // single arg functions can be added here + ("asin", Function::token_from_fn("asin".into(), |x| x.asin())), + ("acos", Function::token_from_fn("acos".into(), |x| x.acos())), + ("atan", Function::token_from_fn("atan".into(), |x| x.atan())), + ("acsc", Function::token_from_fn("acsc".into(), |x| (1./x).asin())), + ("asec", Function::token_from_fn("asec".into(), |x| (1./x).acos())), + ("acot", Function::token_from_fn("acot".into(), |x| (1./x).atan())), + // single arg function s can be added here ].iter().cloned().collect(); } @@ -104,6 +110,7 @@ fn get_operators() -> HashMap { ('-', Operator::token_from_op('-', |x, y| x - y, 2, true)), ('*', Operator::token_from_op('*', |x, y| x * y, 3, true)), ('/', Operator::token_from_op('/', |x, y| x / y, 3, true)), + ('%', Operator::token_from_op('%', |x, y| x % y, 3, true)), ('^', Operator::token_from_op('^', |x, y| x.powf(y) , 4, false)), ].iter().cloned().collect(); } @@ -157,7 +164,7 @@ pub fn lexer(input: &str) -> Result, CalcError> { result.push(Operator::token_from_op('*', |x, y| x * y, 10, true)); } }, - '/' | '*' | '^' => { + '/' | '*' | '%' | '^' => { drain_num_stack(&mut num_vec, &mut result); let operator_token: Token = operators.get(&letter).unwrap().clone(); result.push(operator_token); -- cgit v1.2.3