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