Function in num coil-stdlib

abs

fn abs(int x) -> int
fn abs(float x) -> float
Import
use num::{abs};
Source: 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#

NameType
xint

Returns#

int

fn abs(float x) -> float#

Returns the absolute value of x; -0.0 becomes 0.0.

Parameters#

NameType
xfloat

Returns#

float

Examples#

use num::{abs};
use tests::assert;
assert!(abs(-5) == 5);
assert!(abs(2.5) == 2.5);

See also#

  • int
  • min: Returns the smaller of a and b (a when they are equal).
  • max: Returns the larger of a and b (a when they are equal).
  • round: Rounds x to the nearest whole number; halves round away from zero.
  • clamp: Returns x limited to the range lo..=hi.
  • signum: Returns -1, 0 or 1 by the sign of x.
  • gcd: Returns the greatest common divisor of a and b, which should be non-negative.
  • lcm: Returns the least common multiple of a and b, which should be non-negative; 0 when either is 0.
↑ ↓ navigate ↵ open