@@ -29,6 +29,59 @@ pub trait RealField:
2929 /// Returns the `NaN` value.
3030 fn nan ( ) -> Self ;
3131
32+ /// Returns `true` if this value is `NaN` and false otherwise.
33+ ///
34+ /// ```
35+ /// use deep_causality_num::Float;
36+ /// use core::f64;
37+ ///
38+ /// let nan = f64::NAN;
39+ /// let f = 7.0;
40+ ///
41+ /// assert!(nan.is_nan());
42+ /// assert!(!f.is_nan());
43+ /// ```
44+ fn is_nan ( self ) -> bool ;
45+
46+ /// Returns `true` if this value is positive infinity or negative infinity and
47+ /// false otherwise.
48+ ///
49+ /// ```
50+ /// use deep_causality_num::Float;
51+ /// use core::f32;
52+ ///
53+ /// let f = 7.0f32;
54+ /// let inf: f32 = Float::infinity();
55+ /// let neg_inf: f32 = Float::neg_infinity();
56+ /// let nan: f32 = f32::NAN;
57+ ///
58+ /// assert!(!f.is_infinite());
59+ /// assert!(!nan.is_infinite());
60+ ///
61+ /// assert!(inf.is_infinite());
62+ /// assert!(neg_inf.is_infinite());
63+ /// ```
64+ fn is_infinite ( self ) -> bool ;
65+
66+ /// Returns `true` if this number is neither infinite nor `NaN`.
67+ ///
68+ /// ```
69+ /// use deep_causality_num::Float;
70+ /// use core::f32;
71+ ///
72+ /// let f = 7.0f32;
73+ /// let inf: f32 = Float::infinity();
74+ /// let neg_inf: f32 = Float::neg_infinity();
75+ /// let nan: f32 = f32::NAN;
76+ ///
77+ /// assert!(f.is_finite());
78+ ///
79+ /// assert!(!nan.is_finite());
80+ /// assert!(!inf.is_finite());
81+ /// assert!(!neg_inf.is_finite());
82+ /// ```
83+ fn is_finite ( self ) -> bool ;
84+
3285 fn clamp ( self , min : Self , max : Self ) -> Self ;
3386
3487 /// Computes the principal square root of a number.
@@ -266,14 +319,21 @@ impl RealField for f32 {
266319 f32:: NAN
267320 }
268321
269- #[ inline]
270- fn clamp ( self , min : Self , max : Self ) -> Self {
271- f32:: clamp ( self , min, max)
322+ fn is_nan ( self ) -> bool {
323+ f32:: is_nan ( self )
324+ }
325+
326+ fn is_infinite ( self ) -> bool {
327+ f32:: is_infinite ( self )
328+ }
329+
330+ fn is_finite ( self ) -> bool {
331+ f32:: is_finite ( self )
272332 }
273333
274334 #[ inline]
275- fn abs ( self ) -> Self {
276- self . abs ( )
335+ fn clamp ( self , min : Self , max : Self ) -> Self {
336+ f32 :: clamp ( self , min , max )
277337 }
278338
279339 #[ inline]
@@ -285,6 +345,11 @@ impl RealField for f32 {
285345 return libm:: sqrtf ( self ) ;
286346 }
287347
348+ #[ inline]
349+ fn abs ( self ) -> Self {
350+ self . abs ( )
351+ }
352+
288353 #[ inline]
289354 fn floor ( self ) -> Self {
290355 #[ cfg( feature = "std" ) ]
@@ -357,6 +422,11 @@ impl RealField for f32 {
357422 return libm:: sinf ( self ) ;
358423 }
359424
425+ #[ inline]
426+ fn asin ( self ) -> Self {
427+ f32:: asin ( self )
428+ }
429+
360430 #[ inline]
361431 fn cos ( self ) -> Self {
362432 #[ cfg( feature = "std" ) ]
@@ -411,6 +481,11 @@ impl RealField for f32 {
411481 return libm:: tanhf ( self ) ;
412482 }
413483
484+ #[ inline]
485+ fn atan ( self ) -> Self {
486+ f32:: atan ( self )
487+ }
488+
414489 #[ inline]
415490 fn atan2 ( self , other : Self ) -> Self {
416491 #[ cfg( feature = "std" ) ]
@@ -429,20 +504,10 @@ impl RealField for f32 {
429504 fn e ( ) -> Self {
430505 core:: f32:: consts:: E
431506 }
432-
433507 #[ inline]
434508 fn epsilon ( ) -> Self {
435509 f32:: EPSILON
436510 }
437-
438- #[ inline]
439- fn atan ( self ) -> Self {
440- f32:: atan ( self )
441- }
442- #[ inline]
443- fn asin ( self ) -> Self {
444- f32:: asin ( self )
445- }
446511}
447512
448513// -----------------------------------------------------------------------------
@@ -632,4 +697,16 @@ impl RealField for f64 {
632697 fn asin ( self ) -> Self {
633698 f64:: asin ( self )
634699 }
700+
701+ fn is_nan ( self ) -> bool {
702+ f64:: is_nan ( self )
703+ }
704+
705+ fn is_infinite ( self ) -> bool {
706+ f64:: is_infinite ( self )
707+ }
708+
709+ fn is_finite ( self ) -> bool {
710+ f64:: is_finite ( self )
711+ }
635712}
0 commit comments