File tree Expand file tree Collapse file tree 4 files changed +55
-2
lines changed Expand file tree Collapse file tree 4 files changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -543,6 +543,22 @@ impl Float for f32 {
543
543
fn is_finite ( & self ) -> bool {
544
544
!( self . is_NaN ( ) || self . is_infinite ( ) )
545
545
}
546
+
547
+ ///
548
+ /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
549
+ /// produces a more accurate result with better performance than a separate multiplication
550
+ /// operation followed by an add.
551
+ ///
552
+ #[ inline( always) ]
553
+ fn mul_add ( & self , a : f32 , b : f32 ) -> f32 {
554
+ mul_add ( * self , a, b)
555
+ }
556
+
557
+ /// Returns the next representable floating-point value in the direction of `other`
558
+ #[ inline( always) ]
559
+ fn next_after ( & self , other : f32 ) -> f32 {
560
+ nextafter ( * self , other)
561
+ }
546
562
}
547
563
548
564
//
Original file line number Diff line number Diff line change @@ -583,6 +583,22 @@ impl Float for f64 {
583
583
fn is_finite ( & self ) -> bool {
584
584
!( self . is_NaN ( ) || self . is_infinite ( ) )
585
585
}
586
+
587
+ ///
588
+ /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
589
+ /// produces a more accurate result with better performance than a separate multiplication
590
+ /// operation followed by an add.
591
+ ///
592
+ #[ inline( always) ]
593
+ fn mul_add ( & self , a : f64 , b : f64 ) -> f64 {
594
+ mul_add ( * self , a, b)
595
+ }
596
+
597
+ /// Returns the next representable floating-point value in the direction of `other`
598
+ #[ inline( always) ]
599
+ fn next_after ( & self , other : f64 ) -> f64 {
600
+ nextafter ( * self , other)
601
+ }
586
602
}
587
603
588
604
//
Original file line number Diff line number Diff line change @@ -735,6 +735,22 @@ impl Float for float {
735
735
fn is_finite(&self) -> bool {
736
736
!(self.is_NaN() || self.is_infinite())
737
737
}
738
+
739
+ ///
740
+ /// Fused multiply-add. Computes `(self * a) + b` with only one rounding error. This
741
+ /// produces a more accurate result with better performance than a separate multiplication
742
+ /// operation followed by an add.
743
+ ///
744
+ #[inline(always)]
745
+ fn mul_add(&self, a: float, b: float) -> float {
746
+ mul_add(*self as f64, a as f64, b as f64) as float
747
+ }
748
+
749
+ /// Returns the next representable floating-point value in the direction of `other`
750
+ #[inline(always)]
751
+ fn next_after(&self, other: float) -> float {
752
+ nextafter(*self as f64, other as f64) as float
753
+ }
738
754
}
739
755
740
756
#[cfg(test)]
Original file line number Diff line number Diff line change @@ -105,6 +105,9 @@ pub trait Fractional: Num
105
105
fn recip ( & self ) -> Self ;
106
106
}
107
107
108
+ ///
109
+ /// Defines constants and methods common to real numbers
110
+ ///
108
111
pub trait Real : Signed
109
112
+ Fractional {
110
113
// FIXME (#5527): usages of `int` should be replaced with an associated
@@ -237,8 +240,7 @@ pub trait Int: Integer
237
240
+ BitCount { }
238
241
239
242
///
240
- /// Primitive floating point numbers. This trait should only be implemented
241
- /// for the `f32`, `f64`, and `float` types.
243
+ /// Primitive floating point numbers
242
244
///
243
245
pub trait Float : Real
244
246
+ Signed
@@ -252,6 +254,9 @@ pub trait Float: Real
252
254
fn is_NaN ( & self ) -> bool ;
253
255
fn is_infinite ( & self ) -> bool ;
254
256
fn is_finite ( & self ) -> bool ;
257
+
258
+ fn mul_add ( & self , a : Self , b : Self ) -> Self ;
259
+ fn next_after ( & self , other : Self ) -> Self ;
255
260
}
256
261
257
262
///
You can’t perform that action at this time.
0 commit comments