sign

Function sign 

Source
pub fn sign<R: Float>(x: R) -> R
Expand description

Primal sign.

The primal follows Julia-style sign: it returns signed zero for zero inputs, +1/-1 for positive/negative infinities, and x.signum() otherwise.

The corresponding forward and reverse rules use a zero-gradient policy at every point.

ยงExamples

use chainrules::sign;

assert_eq!(sign(-3.0_f64), -1.0);
assert_eq!(sign(0.0_f64), 0.0);
assert_eq!(sign(-0.0_f64).is_sign_negative(), true);