@@ -240,6 +240,28 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
240240 fn is_normal ( self ) -> bool {
241241 self . classify ( ) == FpCategory :: Normal
242242 }
243+
244+ /// Returns `true` if the number is [subnormal].
245+ ///
246+ /// ```
247+ /// let min = f64::MIN_POSITIVE; // 2.2250738585072014e-308_f64
248+ /// let max = f64::MAX;
249+ /// let lower_than_min = 1.0e-308_f64;
250+ /// let zero = 0.0_f64;
251+ ///
252+ /// assert!(!min.is_subnormal());
253+ /// assert!(!max.is_subnormal());
254+ ///
255+ /// assert!(!zero.is_subnormal());
256+ /// assert!(!f64::NAN.is_subnormal());
257+ /// assert!(!f64::INFINITY.is_subnormal());
258+ /// // Values between `0` and `min` are Subnormal.
259+ /// assert!(lower_than_min.is_subnormal());
260+ /// ```
261+ /// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
262+ fn is_subnormal ( self ) -> bool {
263+ self . classify ( ) == FpCategory :: Subnormal
264+ }
243265
244266 /// Returns the floating point category of the number. If only one property
245267 /// is going to be tested, it is generally faster to use the specific
@@ -900,6 +922,7 @@ impl FloatCore for f64 {
900922 Self :: is_infinite( self ) -> bool ;
901923 Self :: is_finite( self ) -> bool ;
902924 Self :: is_normal( self ) -> bool ;
925+ Self :: is_subnormal( self ) -> bool ;
903926 Self :: classify( self ) -> FpCategory ;
904927 Self :: floor( self ) -> Self ;
905928 Self :: ceil( self ) -> Self ;
@@ -1126,6 +1149,26 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
11261149 /// [subnormal]: http://en.wikipedia.org/wiki/Denormal_number
11271150 fn is_normal ( self ) -> bool ;
11281151
1152+ /// Returns `true` if the number is [subnormal].
1153+ ///
1154+ /// ```
1155+ /// let min = f64::MIN_POSITIVE; // 2.2250738585072014e-308_f64
1156+ /// let max = f64::MAX;
1157+ /// let lower_than_min = 1.0e-308_f64;
1158+ /// let zero = 0.0_f64;
1159+ ///
1160+ /// assert!(!min.is_subnormal());
1161+ /// assert!(!max.is_subnormal());
1162+ ///
1163+ /// assert!(!zero.is_subnormal());
1164+ /// assert!(!f64::NAN.is_subnormal());
1165+ /// assert!(!f64::INFINITY.is_subnormal());
1166+ /// // Values between `0` and `min` are Subnormal.
1167+ /// assert!(lower_than_min.is_subnormal());
1168+ /// ```
1169+ /// [subnormal]: https://en.wikipedia.org/wiki/Denormal_number
1170+ fn is_subnormal ( self ) -> bool ;
1171+
11291172 /// Returns the floating point category of the number. If only one property
11301173 /// is going to be tested, it is generally faster to use the specific
11311174 /// predicate instead.
@@ -1913,6 +1956,7 @@ macro_rules! float_impl_std {
19131956 Self :: is_infinite( self ) -> bool ;
19141957 Self :: is_finite( self ) -> bool ;
19151958 Self :: is_normal( self ) -> bool ;
1959+ Self :: is_subnormal( self ) -> bool ;
19161960 Self :: classify( self ) -> FpCategory ;
19171961 Self :: floor( self ) -> Self ;
19181962 Self :: ceil( self ) -> Self ;
0 commit comments