Skip to content

Commit

Permalink
Merge pull request #572 from Bzero/dimensionful_abs
Browse files Browse the repository at this point in the history
Dimensionful `abs` function
  • Loading branch information
sharkdp authored Sep 24, 2024
2 parents 21b09da + 8467731 commit e61ea62
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions numbat/src/ffi/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn mod_(mut args: Args) -> Result<Value> {
return_quantity!(x_value.rem_euclid(y_value), x.unit().clone())
}

// Similar, but with signature 'Fn[(Scalar) -> Scalar]'
// A simple math function with signature 'Fn[(Scalar) -> Scalar]'
macro_rules! simple_scalar_math_function {
($name:ident, $op:ident) => {
pub fn $name(mut args: Args) -> Result<Value> {
Expand All @@ -25,7 +25,11 @@ macro_rules! simple_scalar_math_function {
};
}

simple_scalar_math_function!(abs, abs);
pub fn abs(mut args: Args) -> Result<Value> {
let arg = quantity_arg!(args);
return_quantity!(arg.unsafe_value().to_f64().abs(), arg.unit().clone())
}

simple_scalar_math_function!(round, round);
simple_scalar_math_function!(floor, floor);
simple_scalar_math_function!(ceil, ceil);
Expand Down

0 comments on commit e61ea62

Please sign in to comment.