From 5e5e060b8af0d20e82bb90a4c46b87251efcf364 Mon Sep 17 00:00:00 2001 From: RanaPriyansh Date: Mon, 21 Sep 2026 02:51:37 +0530 Subject: [PATCH] Clarify signed-zero behavior in Signed predicate documentation --- src/sign.rs | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/sign.rs b/src/sign.rs index a0d6b0fd..4c0c21dd 100644 --- a/src/sign.rs +++ b/src/sign.rs @@ -34,10 +34,46 @@ pub trait Signed: Sized + Num + Neg { /// * `-1` if the number is negative fn signum(&self) -> Self; - /// Returns true if the number is positive and false if the number is zero or negative. + /// Returns `true` if the number is positive. + /// + /// For signed integers, zero is neither positive nor negative. + /// + /// For `f32` and `f64`, the result follows the sign bit. Therefore, `+0.0` is positive, + /// `-0.0` is negative, and positive and negative infinity follow the same rule. NaN values + /// also follow their sign bit. The sign of a NaN produced by arithmetic is not specified here. + /// + /// # Examples + /// + /// ``` + /// use num_traits::Signed; + /// + /// assert!(::is_positive(&0.0)); + /// assert!(::is_positive(&0.0)); + /// assert!(!::is_positive(&-0.0)); + /// assert!(!::is_positive(&-0.0)); + /// assert!(!::is_positive(&0)); + /// ``` fn is_positive(&self) -> bool; - /// Returns true if the number is negative and false if the number is zero or positive. + /// Returns `true` if the number is negative. + /// + /// For signed integers, zero is neither positive nor negative. + /// + /// For `f32` and `f64`, the result follows the sign bit. Therefore, `-0.0` is negative, + /// `+0.0` is positive, and negative and positive infinity follow the same rule. NaN values + /// also follow their sign bit. The sign of a NaN produced by arithmetic is not specified here. + /// + /// # Examples + /// + /// ``` + /// use num_traits::Signed; + /// + /// assert!(!::is_negative(&0.0)); + /// assert!(!::is_negative(&0.0)); + /// assert!(::is_negative(&-0.0)); + /// assert!(::is_negative(&-0.0)); + /// assert!(!::is_negative(&0)); + /// ``` fn is_negative(&self) -> bool; }