@@ -12,20 +12,13 @@ use std::ops::{Add, Div, Mul, Sub};
12
12
13
13
// Note these tolerances make sense around zero, but not for more extreme exponents.
14
14
15
- /// For operations that are near exact, usually not involving math of different
16
- /// signs.
17
- const TOL_PRECISE : f128 = 1e-28 ;
18
-
19
15
/// Default tolerances. Works for values that should be near precise but not exact. Roughly
20
16
/// the precision carried by `100 * 100`.
21
17
const TOL : f128 = 1e-12 ;
22
18
23
- /// Tolerances for math that is allowed to be imprecise, usually due to multiple chained
24
- /// operations.
25
- #[ cfg( not( miri) ) ]
26
- #[ cfg( not( bootstrap) ) ]
27
- #[ cfg( target_has_reliable_f128_math) ]
28
- const TOL_IMPR : f128 = 1e-10 ;
19
+ /// For operations that are near exact, usually not involving math of different
20
+ /// signs.
21
+ const TOL_PRECISE : f128 = 1e-28 ;
29
22
30
23
/// Smallest number
31
24
const TINY_BITS : u128 = 0x1 ;
@@ -517,8 +510,6 @@ fn test_recip() {
517
510
assert_eq ! ( neg_inf. recip( ) , 0.0 ) ;
518
511
}
519
512
520
- // Many math functions allow for less accurate results, so the next tolerance up is used
521
-
522
513
#[ test]
523
514
#[ cfg( not( miri) ) ]
524
515
#[ cfg( not( bootstrap) ) ]
@@ -536,25 +527,6 @@ fn test_powi() {
536
527
assert_eq ! ( neg_inf. powi( 2 ) , inf) ;
537
528
}
538
529
539
- #[ test]
540
- #[ cfg( not( miri) ) ]
541
- #[ cfg( not( bootstrap) ) ]
542
- #[ cfg( target_has_reliable_f128_math) ]
543
- fn test_powf ( ) {
544
- let nan: f128 = f128:: NAN ;
545
- let inf: f128 = f128:: INFINITY ;
546
- let neg_inf: f128 = f128:: NEG_INFINITY ;
547
- assert_eq ! ( 1.0f128 . powf( 1.0 ) , 1.0 ) ;
548
- assert_approx_eq ! ( 3.4f128 . powf( 4.5 ) , 246.40818323761892815995637964326426756 , TOL_IMPR ) ;
549
- assert_approx_eq ! ( 2.7f128 . powf( -3.2 ) , 0.041652009108526178281070304373500889273 , TOL_IMPR ) ;
550
- assert_approx_eq ! ( ( -3.1f128 ) . powf( 2.0 ) , 9.6100000000000005506706202140776519387 , TOL_IMPR ) ;
551
- assert_approx_eq ! ( 5.9f128 . powf( -2.0 ) , 0.028727377190462507313100483690639638451 , TOL_IMPR ) ;
552
- assert_eq ! ( 8.3f128 . powf( 0.0 ) , 1.0 ) ;
553
- assert ! ( nan. powf( 2.0 ) . is_nan( ) ) ;
554
- assert_eq ! ( inf. powf( 2.0 ) , inf) ;
555
- assert_eq ! ( neg_inf. powf( 3.0 ) , neg_inf) ;
556
- }
557
-
558
530
#[ test]
559
531
#[ cfg( not( miri) ) ]
560
532
#[ cfg( not( bootstrap) ) ]
@@ -569,117 +541,6 @@ fn test_sqrt_domain() {
569
541
assert_eq ! ( f128:: INFINITY . sqrt( ) , f128:: INFINITY ) ;
570
542
}
571
543
572
- #[ test]
573
- #[ cfg( not( miri) ) ]
574
- #[ cfg( not( bootstrap) ) ]
575
- #[ cfg( target_has_reliable_f128_math) ]
576
- fn test_exp ( ) {
577
- assert_eq ! ( 1.0 , 0.0f128 . exp( ) ) ;
578
- assert_approx_eq ! ( consts:: E , 1.0f128 . exp( ) , TOL ) ;
579
- assert_approx_eq ! ( 148.41315910257660342111558004055227962348775 , 5.0f128 . exp( ) , TOL ) ;
580
-
581
- let inf: f128 = f128:: INFINITY ;
582
- let neg_inf: f128 = f128:: NEG_INFINITY ;
583
- let nan: f128 = f128:: NAN ;
584
- assert_eq ! ( inf, inf. exp( ) ) ;
585
- assert_eq ! ( 0.0 , neg_inf. exp( ) ) ;
586
- assert ! ( nan. exp( ) . is_nan( ) ) ;
587
- }
588
-
589
- #[ test]
590
- #[ cfg( not( miri) ) ]
591
- #[ cfg( not( bootstrap) ) ]
592
- #[ cfg( target_has_reliable_f128_math) ]
593
- fn test_exp2 ( ) {
594
- assert_eq ! ( 32.0 , 5.0f128 . exp2( ) ) ;
595
- assert_eq ! ( 1.0 , 0.0f128 . exp2( ) ) ;
596
-
597
- let inf: f128 = f128:: INFINITY ;
598
- let neg_inf: f128 = f128:: NEG_INFINITY ;
599
- let nan: f128 = f128:: NAN ;
600
- assert_eq ! ( inf, inf. exp2( ) ) ;
601
- assert_eq ! ( 0.0 , neg_inf. exp2( ) ) ;
602
- assert ! ( nan. exp2( ) . is_nan( ) ) ;
603
- }
604
-
605
- #[ test]
606
- #[ cfg( not( miri) ) ]
607
- #[ cfg( not( bootstrap) ) ]
608
- #[ cfg( target_has_reliable_f128_math) ]
609
- fn test_ln ( ) {
610
- let nan: f128 = f128:: NAN ;
611
- let inf: f128 = f128:: INFINITY ;
612
- let neg_inf: f128 = f128:: NEG_INFINITY ;
613
- assert_approx_eq ! ( 1.0f128 . exp( ) . ln( ) , 1.0 , TOL ) ;
614
- assert ! ( nan. ln( ) . is_nan( ) ) ;
615
- assert_eq ! ( inf. ln( ) , inf) ;
616
- assert ! ( neg_inf. ln( ) . is_nan( ) ) ;
617
- assert ! ( ( -2.3f128 ) . ln( ) . is_nan( ) ) ;
618
- assert_eq ! ( ( -0.0f128 ) . ln( ) , neg_inf) ;
619
- assert_eq ! ( 0.0f128 . ln( ) , neg_inf) ;
620
- assert_approx_eq ! ( 4.0f128 . ln( ) , 1.3862943611198906188344642429163531366 , TOL ) ;
621
- }
622
-
623
- #[ test]
624
- #[ cfg( not( miri) ) ]
625
- #[ cfg( not( bootstrap) ) ]
626
- #[ cfg( target_has_reliable_f128_math) ]
627
- fn test_log ( ) {
628
- let nan: f128 = f128:: NAN ;
629
- let inf: f128 = f128:: INFINITY ;
630
- let neg_inf: f128 = f128:: NEG_INFINITY ;
631
- assert_eq ! ( 10.0f128 . log( 10.0 ) , 1.0 ) ;
632
- assert_approx_eq ! ( 2.3f128 . log( 3.5 ) , 0.66485771361478710036766645911922010272 , TOL ) ;
633
- assert_eq ! ( 1.0f128 . exp( ) . log( 1.0f128 . exp( ) ) , 1.0 ) ;
634
- assert ! ( 1.0f128 . log( 1.0 ) . is_nan( ) ) ;
635
- assert ! ( 1.0f128 . log( -13.9 ) . is_nan( ) ) ;
636
- assert ! ( nan. log( 2.3 ) . is_nan( ) ) ;
637
- assert_eq ! ( inf. log( 10.0 ) , inf) ;
638
- assert ! ( neg_inf. log( 8.8 ) . is_nan( ) ) ;
639
- assert ! ( ( -2.3f128 ) . log( 0.1 ) . is_nan( ) ) ;
640
- assert_eq ! ( ( -0.0f128 ) . log( 2.0 ) , neg_inf) ;
641
- assert_eq ! ( 0.0f128 . log( 7.0 ) , neg_inf) ;
642
- }
643
-
644
- #[ test]
645
- #[ cfg( not( miri) ) ]
646
- #[ cfg( not( bootstrap) ) ]
647
- #[ cfg( target_has_reliable_f128_math) ]
648
- fn test_log2 ( ) {
649
- let nan: f128 = f128:: NAN ;
650
- let inf: f128 = f128:: INFINITY ;
651
- let neg_inf: f128 = f128:: NEG_INFINITY ;
652
- assert_approx_eq ! ( 10.0f128 . log2( ) , 3.32192809488736234787031942948939017 , TOL ) ;
653
- assert_approx_eq ! ( 2.3f128 . log2( ) , 1.2016338611696504130002982471978765921 , TOL ) ;
654
- assert_approx_eq ! ( 1.0f128 . exp( ) . log2( ) , 1.4426950408889634073599246810018921381 , TOL ) ;
655
- assert ! ( nan. log2( ) . is_nan( ) ) ;
656
- assert_eq ! ( inf. log2( ) , inf) ;
657
- assert ! ( neg_inf. log2( ) . is_nan( ) ) ;
658
- assert ! ( ( -2.3f128 ) . log2( ) . is_nan( ) ) ;
659
- assert_eq ! ( ( -0.0f128 ) . log2( ) , neg_inf) ;
660
- assert_eq ! ( 0.0f128 . log2( ) , neg_inf) ;
661
- }
662
-
663
- #[ test]
664
- #[ cfg( not( miri) ) ]
665
- #[ cfg( not( bootstrap) ) ]
666
- #[ cfg( target_has_reliable_f128_math) ]
667
- fn test_log10 ( ) {
668
- let nan: f128 = f128:: NAN ;
669
- let inf: f128 = f128:: INFINITY ;
670
- let neg_inf: f128 = f128:: NEG_INFINITY ;
671
- assert_eq ! ( 10.0f128 . log10( ) , 1.0 ) ;
672
- assert_approx_eq ! ( 2.3f128 . log10( ) , 0.36172783601759284532595218865859309898 , TOL ) ;
673
- assert_approx_eq ! ( 1.0f128 . exp( ) . log10( ) , 0.43429448190325182765112891891660508222 , TOL ) ;
674
- assert_eq ! ( 1.0f128 . log10( ) , 0.0 ) ;
675
- assert ! ( nan. log10( ) . is_nan( ) ) ;
676
- assert_eq ! ( inf. log10( ) , inf) ;
677
- assert ! ( neg_inf. log10( ) . is_nan( ) ) ;
678
- assert ! ( ( -2.3f128 ) . log10( ) . is_nan( ) ) ;
679
- assert_eq ! ( ( -0.0f128 ) . log10( ) , neg_inf) ;
680
- assert_eq ! ( 0.0f128 . log10( ) , neg_inf) ;
681
- }
682
-
683
544
#[ test]
684
545
fn test_to_degrees ( ) {
685
546
let pi: f128 = consts:: PI ;
@@ -712,162 +573,6 @@ fn test_to_radians() {
712
573
assert_eq ! ( neg_inf. to_radians( ) , neg_inf) ;
713
574
}
714
575
715
- #[ test]
716
- #[ cfg( not( miri) ) ]
717
- #[ cfg( not( bootstrap) ) ]
718
- #[ cfg( target_has_reliable_f128_math) ]
719
- fn test_asinh ( ) {
720
- // Lower accuracy results are allowed, use increased tolerances
721
- assert_eq ! ( 0.0f128 . asinh( ) , 0.0f128 ) ;
722
- assert_eq ! ( ( -0.0f128 ) . asinh( ) , -0.0f128 ) ;
723
-
724
- let inf: f128 = f128:: INFINITY ;
725
- let neg_inf: f128 = f128:: NEG_INFINITY ;
726
- let nan: f128 = f128:: NAN ;
727
- assert_eq ! ( inf. asinh( ) , inf) ;
728
- assert_eq ! ( neg_inf. asinh( ) , neg_inf) ;
729
- assert ! ( nan. asinh( ) . is_nan( ) ) ;
730
- assert ! ( ( -0.0f128 ) . asinh( ) . is_sign_negative( ) ) ;
731
-
732
- // issue 63271
733
- assert_approx_eq ! ( 2.0f128 . asinh( ) , 1.443635475178810342493276740273105f128 , TOL_IMPR ) ;
734
- assert_approx_eq ! ( ( -2.0f128 ) . asinh( ) , -1.443635475178810342493276740273105f128 , TOL_IMPR ) ;
735
- // regression test for the catastrophic cancellation fixed in 72486
736
- assert_approx_eq ! (
737
- ( -67452098.07139316f128 ) . asinh( ) ,
738
- -18.720075426274544393985484294000831757220 ,
739
- TOL_IMPR
740
- ) ;
741
-
742
- // test for low accuracy from issue 104548
743
- assert_approx_eq ! ( 60.0f128 , 60.0f128 . sinh( ) . asinh( ) , TOL_IMPR ) ;
744
- // mul needed for approximate comparison to be meaningful
745
- assert_approx_eq ! ( 1.0f128 , 1e-15f128 . sinh( ) . asinh( ) * 1e15f128 , TOL_IMPR ) ;
746
- }
747
-
748
- #[ test]
749
- #[ cfg( not( miri) ) ]
750
- #[ cfg( not( bootstrap) ) ]
751
- #[ cfg( target_has_reliable_f128_math) ]
752
- fn test_acosh ( ) {
753
- assert_eq ! ( 1.0f128 . acosh( ) , 0.0f128 ) ;
754
- assert ! ( 0.999f128 . acosh( ) . is_nan( ) ) ;
755
-
756
- let inf: f128 = f128:: INFINITY ;
757
- let neg_inf: f128 = f128:: NEG_INFINITY ;
758
- let nan: f128 = f128:: NAN ;
759
- assert_eq ! ( inf. acosh( ) , inf) ;
760
- assert ! ( neg_inf. acosh( ) . is_nan( ) ) ;
761
- assert ! ( nan. acosh( ) . is_nan( ) ) ;
762
- assert_approx_eq ! ( 2.0f128 . acosh( ) , 1.31695789692481670862504634730796844f128 , TOL_IMPR ) ;
763
- assert_approx_eq ! ( 3.0f128 . acosh( ) , 1.76274717403908605046521864995958461f128 , TOL_IMPR ) ;
764
-
765
- // test for low accuracy from issue 104548
766
- assert_approx_eq ! ( 60.0f128 , 60.0f128 . cosh( ) . acosh( ) , TOL_IMPR ) ;
767
- }
768
-
769
- #[ test]
770
- #[ cfg( not( miri) ) ]
771
- #[ cfg( not( bootstrap) ) ]
772
- #[ cfg( target_has_reliable_f128_math) ]
773
- fn test_atanh ( ) {
774
- assert_eq ! ( 0.0f128 . atanh( ) , 0.0f128 ) ;
775
- assert_eq ! ( ( -0.0f128 ) . atanh( ) , -0.0f128 ) ;
776
-
777
- let inf: f128 = f128:: INFINITY ;
778
- let neg_inf: f128 = f128:: NEG_INFINITY ;
779
- let nan: f128 = f128:: NAN ;
780
- assert_eq ! ( 1.0f128 . atanh( ) , inf) ;
781
- assert_eq ! ( ( -1.0f128 ) . atanh( ) , neg_inf) ;
782
- assert ! ( 2 f128. atanh( ) . atanh( ) . is_nan( ) ) ;
783
- assert ! ( ( -2 f128) . atanh( ) . atanh( ) . is_nan( ) ) ;
784
- assert ! ( inf. atanh( ) . is_nan( ) ) ;
785
- assert ! ( neg_inf. atanh( ) . is_nan( ) ) ;
786
- assert ! ( nan. atanh( ) . is_nan( ) ) ;
787
- assert_approx_eq ! ( 0.5f128 . atanh( ) , 0.54930614433405484569762261846126285f128 , TOL_IMPR ) ;
788
- assert_approx_eq ! ( ( -0.5f128 ) . atanh( ) , -0.54930614433405484569762261846126285f128 , TOL_IMPR ) ;
789
- }
790
-
791
- #[ test]
792
- #[ cfg( not( miri) ) ]
793
- #[ cfg( not( bootstrap) ) ]
794
- #[ cfg( target_has_reliable_f128_math) ]
795
- fn test_gamma ( ) {
796
- // precision can differ among platforms
797
- assert_approx_eq ! ( 1.0f128 . gamma( ) , 1.0f128 , TOL_IMPR ) ;
798
- assert_approx_eq ! ( 2.0f128 . gamma( ) , 1.0f128 , TOL_IMPR ) ;
799
- assert_approx_eq ! ( 3.0f128 . gamma( ) , 2.0f128 , TOL_IMPR ) ;
800
- assert_approx_eq ! ( 4.0f128 . gamma( ) , 6.0f128 , TOL_IMPR ) ;
801
- assert_approx_eq ! ( 5.0f128 . gamma( ) , 24.0f128 , TOL_IMPR ) ;
802
- assert_approx_eq ! ( 0.5f128 . gamma( ) , consts:: PI . sqrt( ) , TOL_IMPR ) ;
803
- assert_approx_eq ! ( ( -0.5f128 ) . gamma( ) , -2.0 * consts:: PI . sqrt( ) , TOL_IMPR ) ;
804
- assert_eq ! ( 0.0f128 . gamma( ) , f128:: INFINITY ) ;
805
- assert_eq ! ( ( -0.0f128 ) . gamma( ) , f128:: NEG_INFINITY ) ;
806
- assert ! ( ( -1.0f128 ) . gamma( ) . is_nan( ) ) ;
807
- assert ! ( ( -2.0f128 ) . gamma( ) . is_nan( ) ) ;
808
- assert ! ( f128:: NAN . gamma( ) . is_nan( ) ) ;
809
- assert ! ( f128:: NEG_INFINITY . gamma( ) . is_nan( ) ) ;
810
- assert_eq ! ( f128:: INFINITY . gamma( ) , f128:: INFINITY ) ;
811
- assert_eq ! ( 1760.9f128 . gamma( ) , f128:: INFINITY ) ;
812
- }
813
-
814
- #[ test]
815
- #[ cfg( not( miri) ) ]
816
- #[ cfg( not( bootstrap) ) ]
817
- #[ cfg( target_has_reliable_f128_math) ]
818
- fn test_ln_gamma ( ) {
819
- assert_approx_eq ! ( 1.0f128 . ln_gamma( ) . 0 , 0.0f128 , TOL_IMPR ) ;
820
- assert_eq ! ( 1.0f128 . ln_gamma( ) . 1 , 1 ) ;
821
- assert_approx_eq ! ( 2.0f128 . ln_gamma( ) . 0 , 0.0f128 , TOL_IMPR ) ;
822
- assert_eq ! ( 2.0f128 . ln_gamma( ) . 1 , 1 ) ;
823
- assert_approx_eq ! ( 3.0f128 . ln_gamma( ) . 0 , 2.0f128 . ln( ) , TOL_IMPR ) ;
824
- assert_eq ! ( 3.0f128 . ln_gamma( ) . 1 , 1 ) ;
825
- assert_approx_eq ! ( ( -0.5f128 ) . ln_gamma( ) . 0 , ( 2.0 * consts:: PI . sqrt( ) ) . ln( ) , TOL_IMPR ) ;
826
- assert_eq ! ( ( -0.5f128 ) . ln_gamma( ) . 1 , -1 ) ;
827
- }
828
-
829
- #[ test]
830
- fn test_real_consts ( ) {
831
- let pi: f128 = consts:: PI ;
832
- let frac_pi_2: f128 = consts:: FRAC_PI_2 ;
833
- let frac_pi_3: f128 = consts:: FRAC_PI_3 ;
834
- let frac_pi_4: f128 = consts:: FRAC_PI_4 ;
835
- let frac_pi_6: f128 = consts:: FRAC_PI_6 ;
836
- let frac_pi_8: f128 = consts:: FRAC_PI_8 ;
837
- let frac_1_pi: f128 = consts:: FRAC_1_PI ;
838
- let frac_2_pi: f128 = consts:: FRAC_2_PI ;
839
-
840
- assert_approx_eq ! ( frac_pi_2, pi / 2 f128, TOL_PRECISE ) ;
841
- assert_approx_eq ! ( frac_pi_3, pi / 3 f128, TOL_PRECISE ) ;
842
- assert_approx_eq ! ( frac_pi_4, pi / 4 f128, TOL_PRECISE ) ;
843
- assert_approx_eq ! ( frac_pi_6, pi / 6 f128, TOL_PRECISE ) ;
844
- assert_approx_eq ! ( frac_pi_8, pi / 8 f128, TOL_PRECISE ) ;
845
- assert_approx_eq ! ( frac_1_pi, 1 f128 / pi, TOL_PRECISE ) ;
846
- assert_approx_eq ! ( frac_2_pi, 2 f128 / pi, TOL_PRECISE ) ;
847
-
848
- #[ cfg( not( miri) ) ]
849
- #[ cfg( not( bootstrap) ) ]
850
- #[ cfg( target_has_reliable_f128_math) ]
851
- {
852
- let frac_2_sqrtpi: f128 = consts:: FRAC_2_SQRT_PI ;
853
- let sqrt2: f128 = consts:: SQRT_2 ;
854
- let frac_1_sqrt2: f128 = consts:: FRAC_1_SQRT_2 ;
855
- let e: f128 = consts:: E ;
856
- let log2_e: f128 = consts:: LOG2_E ;
857
- let log10_e: f128 = consts:: LOG10_E ;
858
- let ln_2: f128 = consts:: LN_2 ;
859
- let ln_10: f128 = consts:: LN_10 ;
860
-
861
- assert_approx_eq ! ( frac_2_sqrtpi, 2 f128 / pi. sqrt( ) , TOL_PRECISE ) ;
862
- assert_approx_eq ! ( sqrt2, 2 f128. sqrt( ) , TOL_PRECISE ) ;
863
- assert_approx_eq ! ( frac_1_sqrt2, 1 f128 / 2 f128. sqrt( ) , TOL_PRECISE ) ;
864
- assert_approx_eq ! ( log2_e, e. log2( ) , TOL_PRECISE ) ;
865
- assert_approx_eq ! ( log10_e, e. log10( ) , TOL_PRECISE ) ;
866
- assert_approx_eq ! ( ln_2, 2 f128. ln( ) , TOL_PRECISE ) ;
867
- assert_approx_eq ! ( ln_10, 10 f128. ln( ) , TOL_PRECISE ) ;
868
- }
869
- }
870
-
871
576
#[ test]
872
577
fn test_float_bits_conv ( ) {
873
578
assert_eq ! ( ( 1 f128) . to_bits( ) , 0x3fff0000000000000000000000000000 ) ;
0 commit comments