1
1
#![ feature( stmt_expr_attributes) ]
2
2
#![ feature( float_gamma) ]
3
+ #![ feature( core_intrinsics) ]
3
4
#![ allow( arithmetic_overflow) ]
4
5
5
6
use std:: fmt:: Debug ;
@@ -22,6 +23,8 @@ fn main() {
22
23
rounding ( ) ;
23
24
mul_add ( ) ;
24
25
libm ( ) ;
26
+ test_fast ( ) ;
27
+ test_algebraic ( ) ;
25
28
}
26
29
27
30
// Helper function to avoid promotion so that this tests "run-time" casts, not CTFE.
@@ -751,3 +754,67 @@ pub fn libm() {
751
754
assert_approx_eq ! ( val, ( 2.0 * f64 :: consts:: PI . sqrt( ) ) . ln( ) ) ;
752
755
assert_eq ! ( sign, -1 ) ;
753
756
}
757
+
758
+ fn test_fast ( ) {
759
+ use std:: intrinsics:: { fadd_fast, fdiv_fast, fmul_fast, frem_fast, fsub_fast} ;
760
+
761
+ #[ inline( never) ]
762
+ pub fn test_operations_f64 ( a : f64 , b : f64 ) {
763
+ // make sure they all map to the correct operation
764
+ unsafe {
765
+ assert_eq ! ( fadd_fast( a, b) , a + b) ;
766
+ assert_eq ! ( fsub_fast( a, b) , a - b) ;
767
+ assert_eq ! ( fmul_fast( a, b) , a * b) ;
768
+ assert_eq ! ( fdiv_fast( a, b) , a / b) ;
769
+ assert_eq ! ( frem_fast( a, b) , a % b) ;
770
+ }
771
+ }
772
+
773
+ #[ inline( never) ]
774
+ pub fn test_operations_f32 ( a : f32 , b : f32 ) {
775
+ // make sure they all map to the correct operation
776
+ unsafe {
777
+ assert_eq ! ( fadd_fast( a, b) , a + b) ;
778
+ assert_eq ! ( fsub_fast( a, b) , a - b) ;
779
+ assert_eq ! ( fmul_fast( a, b) , a * b) ;
780
+ assert_eq ! ( fdiv_fast( a, b) , a / b) ;
781
+ assert_eq ! ( frem_fast( a, b) , a % b) ;
782
+ }
783
+ }
784
+
785
+ test_operations_f64 ( 1. , 2. ) ;
786
+ test_operations_f64 ( 10. , 5. ) ;
787
+ test_operations_f32 ( 11. , 2. ) ;
788
+ test_operations_f32 ( 10. , 15. ) ;
789
+ }
790
+
791
+ fn test_algebraic ( ) {
792
+ use std:: intrinsics:: {
793
+ fadd_algebraic, fdiv_algebraic, fmul_algebraic, frem_algebraic, fsub_algebraic,
794
+ } ;
795
+
796
+ #[ inline( never) ]
797
+ pub fn test_operations_f64 ( a : f64 , b : f64 ) {
798
+ // make sure they all map to the correct operation
799
+ assert_eq ! ( fadd_algebraic( a, b) , a + b) ;
800
+ assert_eq ! ( fsub_algebraic( a, b) , a - b) ;
801
+ assert_eq ! ( fmul_algebraic( a, b) , a * b) ;
802
+ assert_eq ! ( fdiv_algebraic( a, b) , a / b) ;
803
+ assert_eq ! ( frem_algebraic( a, b) , a % b) ;
804
+ }
805
+
806
+ #[ inline( never) ]
807
+ pub fn test_operations_f32 ( a : f32 , b : f32 ) {
808
+ // make sure they all map to the correct operation
809
+ assert_eq ! ( fadd_algebraic( a, b) , a + b) ;
810
+ assert_eq ! ( fsub_algebraic( a, b) , a - b) ;
811
+ assert_eq ! ( fmul_algebraic( a, b) , a * b) ;
812
+ assert_eq ! ( fdiv_algebraic( a, b) , a / b) ;
813
+ assert_eq ! ( frem_algebraic( a, b) , a % b) ;
814
+ }
815
+
816
+ test_operations_f64 ( 1. , 2. ) ;
817
+ test_operations_f64 ( 10. , 5. ) ;
818
+ test_operations_f32 ( 11. , 2. ) ;
819
+ test_operations_f32 ( 10. , 15. ) ;
820
+ }
0 commit comments