Function in num coil-stdlib

signum

fn signum(int x) -> int
fn signum(float x) -> float
Import
use num::{signum};
Source: src/num.hy

Returns -1, 0 or 1 by the sign of x.

fn signum(int x) -> int#

Parameters#

NameType
xint

Returns#

int

fn signum(float x) -> float#

Returns -1.0, 0.0 or 1.0 by the sign of x; a zero keeps its sign.

Parameters#

NameType
xfloat

Returns#

float

Examples#

use num::{signum};
use tests::assert;
assert!(signum(-8) == -1);
assert!(signum(0) == 0);

See also#

  • abs: Returns the absolute value of x.
  • 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.
  • 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.
  • trunc: Removes the fractional part of x, rounding toward zero.
↑ ↓ navigate ↵ open