Skip to content

Commit

Permalink
all fixes after Vitaly's review are done
Browse files Browse the repository at this point in the history
  • Loading branch information
Innokenty committed Nov 20, 2024
1 parent 2d80c1f commit ccdbfe8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/src/metta/runner/stdlib_minimal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1822,9 +1822,9 @@ pub fn register_common_tokens(tref: &mut Tokenizer, _tokenizer: Shared<Tokenizer
tref.register_token(regex(r"isnan-math"), move |_| { isnan_math_op.clone() });
let isinf_math_op = Atom::gnd(stdlib_math::IsInfMathOp{});
tref.register_token(regex(r"isinf-math"), move |_| { isinf_math_op.clone() });
tref.register_token(regex(r"const_pi"),
tref.register_token(regex(r"consts_PI"),
|_| { Atom::gnd(Number::Float(std::f64::consts::PI)) });
tref.register_token(regex(r"const_e"),
tref.register_token(regex(r"consts_EXP"),
|_| { Atom::gnd(Number::Float(std::f64::consts::E)) });

#[cfg(feature = "pkg_mgmt")]
Expand Down
7 changes: 5 additions & 2 deletions lib/src/metta/runner/stdlib_minimal/stdlib_math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ impl Grounded for AbsMathOp {
impl CustomExecute for AbsMathOp {
fn execute(&self, args: &[Atom]) -> Result<Vec<Atom>, ExecError> {
let arg_error = || ExecError::from("abs-math expects one argument: number");
let input: f64 = args.get(0).and_then(Number::from_atom).ok_or_else(arg_error)?.into();
Ok(vec![Atom::gnd(Number::Float(input.abs()))])
let input = args.get(0).and_then(Number::from_atom).ok_or_else(arg_error)?;
match input {
Number::Integer(n) => Ok(vec![Atom::gnd(Number::Integer(n.abs()))]),
Number::Float(f) => Ok(vec![Atom::gnd(Number::Float(f.abs()))])
}
}
}

Expand Down

0 comments on commit ccdbfe8

Please sign in to comment.