@@ -240,6 +240,28 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
240
240
fn is_normal ( self ) -> bool {
241
241
self . classify ( ) == FpCategory :: Normal
242
242
}
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
+ }
243
265
244
266
/// Returns the floating point category of the number. If only one property
245
267
/// is going to be tested, it is generally faster to use the specific
@@ -900,6 +922,7 @@ impl FloatCore for f64 {
900
922
Self :: is_infinite( self ) -> bool ;
901
923
Self :: is_finite( self ) -> bool ;
902
924
Self :: is_normal( self ) -> bool ;
925
+ Self :: is_subnormal( self ) -> bool ;
903
926
Self :: classify( self ) -> FpCategory ;
904
927
Self :: floor( self ) -> Self ;
905
928
Self :: ceil( self ) -> Self ;
@@ -1126,6 +1149,26 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
1126
1149
/// [subnormal]: http://en.wikipedia.org/wiki/Denormal_number
1127
1150
fn is_normal ( self ) -> bool ;
1128
1151
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
+
1129
1172
/// Returns the floating point category of the number. If only one property
1130
1173
/// is going to be tested, it is generally faster to use the specific
1131
1174
/// predicate instead.
@@ -1913,6 +1956,7 @@ macro_rules! float_impl_std {
1913
1956
Self :: is_infinite( self ) -> bool ;
1914
1957
Self :: is_finite( self ) -> bool ;
1915
1958
Self :: is_normal( self ) -> bool ;
1959
+ Self :: is_subnormal( self ) -> bool ;
1916
1960
Self :: classify( self ) -> FpCategory ;
1917
1961
Self :: floor( self ) -> Self ;
1918
1962
Self :: ceil( self ) -> Self ;
0 commit comments