abs
fn abs(int x) -> intfn abs(float x) -> float Import
Source: use num::{abs}; src/num.hy Returns the absolute value of x.
Panics with integer overflow for the smallest int, whose absolute value does not fit.
fn abs(int x) -> int#
Parameters#
| Name | Type |
|---|---|
x | int |
Returns#
int
fn abs(float x) -> float#
Returns the absolute value of x; -0.0 becomes 0.0.
Parameters#
| Name | Type |
|---|---|
x | float |
Returns#
float
Examples#
use num::{abs};
use tests::assert;
assert!(abs(-5) == 5);
assert!(abs(2.5) == 2.5);
See also#
intmin: Returns the smaller ofaandb(awhen they are equal).max: Returns the larger ofaandb(awhen they are equal).round: Roundsxto the nearest whole number; halves round away from zero.clamp: Returnsxlimited to the rangelo..=hi.signum: Returns-1,0or1by the sign ofx.gcd: Returns the greatest common divisor ofaandb, which should be non-negative.lcm: Returns the least common multiple ofaandb, which should be non-negative;0when either is0.