@@ -17,11 +17,6 @@ const TOL_PRECISE: f128 = 1e-28;
17
17
/// the precision carried by `100 * 100`.
18
18
const TOL : f128 = 1e-12 ;
19
19
20
- /// Tolerances for math that is allowed to be imprecise, usually due to multiple chained
21
- /// operations.
22
- #[ cfg( reliable_f128_math) ]
23
- const TOL_IMPR : f128 = 1e-10 ;
24
-
25
20
/// Smallest number
26
21
const TINY_BITS : u128 = 0x1 ;
27
22
@@ -460,7 +455,7 @@ fn test_mul_add() {
460
455
}
461
456
462
457
#[ test]
463
- #[ cfg( reliable_f16_math ) ]
458
+ #[ cfg( reliable_f128_math ) ]
464
459
fn test_recip ( ) {
465
460
let nan: f128 = f128:: NAN ;
466
461
let inf: f128 = f128:: INFINITY ;
@@ -479,8 +474,6 @@ fn test_recip() {
479
474
assert_eq ! ( neg_inf. recip( ) , 0.0 ) ;
480
475
}
481
476
482
- // Many math functions allow for less accurate results, so the next tolerance up is used
483
-
484
477
#[ test]
485
478
#[ cfg( reliable_f128_math) ]
486
479
fn test_powi ( ) {
@@ -496,23 +489,6 @@ fn test_powi() {
496
489
assert_eq ! ( neg_inf. powi( 2 ) , inf) ;
497
490
}
498
491
499
- #[ test]
500
- #[ cfg( reliable_f128_math) ]
501
- fn test_powf ( ) {
502
- let nan: f128 = f128:: NAN ;
503
- let inf: f128 = f128:: INFINITY ;
504
- let neg_inf: f128 = f128:: NEG_INFINITY ;
505
- assert_eq ! ( 1.0f128 . powf( 1.0 ) , 1.0 ) ;
506
- assert_approx_eq ! ( 3.4f128 . powf( 4.5 ) , 246.40818323761892815995637964326426756 , TOL_IMPR ) ;
507
- assert_approx_eq ! ( 2.7f128 . powf( -3.2 ) , 0.041652009108526178281070304373500889273 , TOL_IMPR ) ;
508
- assert_approx_eq ! ( ( -3.1f128 ) . powf( 2.0 ) , 9.6100000000000005506706202140776519387 , TOL_IMPR ) ;
509
- assert_approx_eq ! ( 5.9f128 . powf( -2.0 ) , 0.028727377190462507313100483690639638451 , TOL_IMPR ) ;
510
- assert_eq ! ( 8.3f128 . powf( 0.0 ) , 1.0 ) ;
511
- assert ! ( nan. powf( 2.0 ) . is_nan( ) ) ;
512
- assert_eq ! ( inf. powf( 2.0 ) , inf) ;
513
- assert_eq ! ( neg_inf. powf( 3.0 ) , neg_inf) ;
514
- }
515
-
516
492
#[ test]
517
493
#[ cfg( reliable_f128_math) ]
518
494
fn test_sqrt_domain ( ) {
@@ -525,105 +501,6 @@ fn test_sqrt_domain() {
525
501
assert_eq ! ( f128:: INFINITY . sqrt( ) , f128:: INFINITY ) ;
526
502
}
527
503
528
- #[ test]
529
- #[ cfg( reliable_f128_math) ]
530
- fn test_exp ( ) {
531
- assert_eq ! ( 1.0 , 0.0f128 . exp( ) ) ;
532
- assert_approx_eq ! ( consts:: E , 1.0f128 . exp( ) , TOL ) ;
533
- assert_approx_eq ! ( 148.41315910257660342111558004055227962348775 , 5.0f128 . exp( ) , TOL ) ;
534
-
535
- let inf: f128 = f128:: INFINITY ;
536
- let neg_inf: f128 = f128:: NEG_INFINITY ;
537
- let nan: f128 = f128:: NAN ;
538
- assert_eq ! ( inf, inf. exp( ) ) ;
539
- assert_eq ! ( 0.0 , neg_inf. exp( ) ) ;
540
- assert ! ( nan. exp( ) . is_nan( ) ) ;
541
- }
542
-
543
- #[ test]
544
- #[ cfg( reliable_f128_math) ]
545
- fn test_exp2 ( ) {
546
- assert_eq ! ( 32.0 , 5.0f128 . exp2( ) ) ;
547
- assert_eq ! ( 1.0 , 0.0f128 . exp2( ) ) ;
548
-
549
- let inf: f128 = f128:: INFINITY ;
550
- let neg_inf: f128 = f128:: NEG_INFINITY ;
551
- let nan: f128 = f128:: NAN ;
552
- assert_eq ! ( inf, inf. exp2( ) ) ;
553
- assert_eq ! ( 0.0 , neg_inf. exp2( ) ) ;
554
- assert ! ( nan. exp2( ) . is_nan( ) ) ;
555
- }
556
-
557
- #[ test]
558
- #[ cfg( reliable_f128_math) ]
559
- fn test_ln ( ) {
560
- let nan: f128 = f128:: NAN ;
561
- let inf: f128 = f128:: INFINITY ;
562
- let neg_inf: f128 = f128:: NEG_INFINITY ;
563
- assert_approx_eq ! ( 1.0f128 . exp( ) . ln( ) , 1.0 , TOL ) ;
564
- assert ! ( nan. ln( ) . is_nan( ) ) ;
565
- assert_eq ! ( inf. ln( ) , inf) ;
566
- assert ! ( neg_inf. ln( ) . is_nan( ) ) ;
567
- assert ! ( ( -2.3f128 ) . ln( ) . is_nan( ) ) ;
568
- assert_eq ! ( ( -0.0f128 ) . ln( ) , neg_inf) ;
569
- assert_eq ! ( 0.0f128 . ln( ) , neg_inf) ;
570
- assert_approx_eq ! ( 4.0f128 . ln( ) , 1.3862943611198906188344642429163531366 , TOL ) ;
571
- }
572
-
573
- #[ test]
574
- #[ cfg( reliable_f128_math) ]
575
- fn test_log ( ) {
576
- let nan: f128 = f128:: NAN ;
577
- let inf: f128 = f128:: INFINITY ;
578
- let neg_inf: f128 = f128:: NEG_INFINITY ;
579
- assert_eq ! ( 10.0f128 . log( 10.0 ) , 1.0 ) ;
580
- assert_approx_eq ! ( 2.3f128 . log( 3.5 ) , 0.66485771361478710036766645911922010272 , TOL ) ;
581
- assert_eq ! ( 1.0f128 . exp( ) . log( 1.0f128 . exp( ) ) , 1.0 ) ;
582
- assert ! ( 1.0f128 . log( 1.0 ) . is_nan( ) ) ;
583
- assert ! ( 1.0f128 . log( -13.9 ) . is_nan( ) ) ;
584
- assert ! ( nan. log( 2.3 ) . is_nan( ) ) ;
585
- assert_eq ! ( inf. log( 10.0 ) , inf) ;
586
- assert ! ( neg_inf. log( 8.8 ) . is_nan( ) ) ;
587
- assert ! ( ( -2.3f128 ) . log( 0.1 ) . is_nan( ) ) ;
588
- assert_eq ! ( ( -0.0f128 ) . log( 2.0 ) , neg_inf) ;
589
- assert_eq ! ( 0.0f128 . log( 7.0 ) , neg_inf) ;
590
- }
591
-
592
- #[ test]
593
- #[ cfg( reliable_f128_math) ]
594
- fn test_log2 ( ) {
595
- let nan: f128 = f128:: NAN ;
596
- let inf: f128 = f128:: INFINITY ;
597
- let neg_inf: f128 = f128:: NEG_INFINITY ;
598
- assert_approx_eq ! ( 10.0f128 . log2( ) , 3.32192809488736234787031942948939017 , TOL ) ;
599
- assert_approx_eq ! ( 2.3f128 . log2( ) , 1.2016338611696504130002982471978765921 , TOL ) ;
600
- assert_approx_eq ! ( 1.0f128 . exp( ) . log2( ) , 1.4426950408889634073599246810018921381 , TOL ) ;
601
- assert ! ( nan. log2( ) . is_nan( ) ) ;
602
- assert_eq ! ( inf. log2( ) , inf) ;
603
- assert ! ( neg_inf. log2( ) . is_nan( ) ) ;
604
- assert ! ( ( -2.3f128 ) . log2( ) . is_nan( ) ) ;
605
- assert_eq ! ( ( -0.0f128 ) . log2( ) , neg_inf) ;
606
- assert_eq ! ( 0.0f128 . log2( ) , neg_inf) ;
607
- }
608
-
609
- #[ test]
610
- #[ cfg( reliable_f128_math) ]
611
- fn test_log10 ( ) {
612
- let nan: f128 = f128:: NAN ;
613
- let inf: f128 = f128:: INFINITY ;
614
- let neg_inf: f128 = f128:: NEG_INFINITY ;
615
- assert_eq ! ( 10.0f128 . log10( ) , 1.0 ) ;
616
- assert_approx_eq ! ( 2.3f128 . log10( ) , 0.36172783601759284532595218865859309898 , TOL ) ;
617
- assert_approx_eq ! ( 1.0f128 . exp( ) . log10( ) , 0.43429448190325182765112891891660508222 , TOL ) ;
618
- assert_eq ! ( 1.0f128 . log10( ) , 0.0 ) ;
619
- assert ! ( nan. log10( ) . is_nan( ) ) ;
620
- assert_eq ! ( inf. log10( ) , inf) ;
621
- assert ! ( neg_inf. log10( ) . is_nan( ) ) ;
622
- assert ! ( ( -2.3f128 ) . log10( ) . is_nan( ) ) ;
623
- assert_eq ! ( ( -0.0f128 ) . log10( ) , neg_inf) ;
624
- assert_eq ! ( 0.0f128 . log10( ) , neg_inf) ;
625
- }
626
-
627
504
#[ test]
628
505
fn test_to_degrees ( ) {
629
506
let pi: f128 = consts:: PI ;
@@ -656,150 +533,6 @@ fn test_to_radians() {
656
533
assert_eq ! ( neg_inf. to_radians( ) , neg_inf) ;
657
534
}
658
535
659
- #[ test]
660
- #[ cfg( reliable_f128_math) ]
661
- fn test_asinh ( ) {
662
- // Lower accuracy results are allowed, use increased tolerances
663
- assert_eq ! ( 0.0f128 . asinh( ) , 0.0f128 ) ;
664
- assert_eq ! ( ( -0.0f128 ) . asinh( ) , -0.0f128 ) ;
665
-
666
- let inf: f128 = f128:: INFINITY ;
667
- let neg_inf: f128 = f128:: NEG_INFINITY ;
668
- let nan: f128 = f128:: NAN ;
669
- assert_eq ! ( inf. asinh( ) , inf) ;
670
- assert_eq ! ( neg_inf. asinh( ) , neg_inf) ;
671
- assert ! ( nan. asinh( ) . is_nan( ) ) ;
672
- assert ! ( ( -0.0f128 ) . asinh( ) . is_sign_negative( ) ) ;
673
-
674
- // issue 63271
675
- assert_approx_eq ! ( 2.0f128 . asinh( ) , 1.443635475178810342493276740273105f128 , TOL_IMPR ) ;
676
- assert_approx_eq ! ( ( -2.0f128 ) . asinh( ) , -1.443635475178810342493276740273105f128 , TOL_IMPR ) ;
677
- // regression test for the catastrophic cancellation fixed in 72486
678
- assert_approx_eq ! (
679
- ( -67452098.07139316f128 ) . asinh( ) ,
680
- -18.720075426274544393985484294000831757220 ,
681
- TOL_IMPR
682
- ) ;
683
-
684
- // test for low accuracy from issue 104548
685
- assert_approx_eq ! ( 60.0f128 , 60.0f128 . sinh( ) . asinh( ) , TOL_IMPR ) ;
686
- // mul needed for approximate comparison to be meaningful
687
- assert_approx_eq ! ( 1.0f128 , 1e-15f128 . sinh( ) . asinh( ) * 1e15f128 , TOL_IMPR ) ;
688
- }
689
-
690
- #[ test]
691
- #[ cfg( reliable_f128_math) ]
692
- fn test_acosh ( ) {
693
- assert_eq ! ( 1.0f128 . acosh( ) , 0.0f128 ) ;
694
- assert ! ( 0.999f128 . acosh( ) . is_nan( ) ) ;
695
-
696
- let inf: f128 = f128:: INFINITY ;
697
- let neg_inf: f128 = f128:: NEG_INFINITY ;
698
- let nan: f128 = f128:: NAN ;
699
- assert_eq ! ( inf. acosh( ) , inf) ;
700
- assert ! ( neg_inf. acosh( ) . is_nan( ) ) ;
701
- assert ! ( nan. acosh( ) . is_nan( ) ) ;
702
- assert_approx_eq ! ( 2.0f128 . acosh( ) , 1.31695789692481670862504634730796844f128 , TOL_IMPR ) ;
703
- assert_approx_eq ! ( 3.0f128 . acosh( ) , 1.76274717403908605046521864995958461f128 , TOL_IMPR ) ;
704
-
705
- // test for low accuracy from issue 104548
706
- assert_approx_eq ! ( 60.0f128 , 60.0f128 . cosh( ) . acosh( ) , TOL_IMPR ) ;
707
- }
708
-
709
- #[ test]
710
- #[ cfg( reliable_f128_math) ]
711
- fn test_atanh ( ) {
712
- assert_eq ! ( 0.0f128 . atanh( ) , 0.0f128 ) ;
713
- assert_eq ! ( ( -0.0f128 ) . atanh( ) , -0.0f128 ) ;
714
-
715
- let inf: f128 = f128:: INFINITY ;
716
- let neg_inf: f128 = f128:: NEG_INFINITY ;
717
- let nan: f128 = f128:: NAN ;
718
- assert_eq ! ( 1.0f128 . atanh( ) , inf) ;
719
- assert_eq ! ( ( -1.0f128 ) . atanh( ) , neg_inf) ;
720
- assert ! ( 2 f128. atanh( ) . atanh( ) . is_nan( ) ) ;
721
- assert ! ( ( -2 f128) . atanh( ) . atanh( ) . is_nan( ) ) ;
722
- assert ! ( inf. atanh( ) . is_nan( ) ) ;
723
- assert ! ( neg_inf. atanh( ) . is_nan( ) ) ;
724
- assert ! ( nan. atanh( ) . is_nan( ) ) ;
725
- assert_approx_eq ! ( 0.5f128 . atanh( ) , 0.54930614433405484569762261846126285f128 , TOL_IMPR ) ;
726
- assert_approx_eq ! ( ( -0.5f128 ) . atanh( ) , -0.54930614433405484569762261846126285f128 , TOL_IMPR ) ;
727
- }
728
-
729
- #[ test]
730
- #[ cfg( reliable_f128_math) ]
731
- fn test_gamma ( ) {
732
- // precision can differ among platforms
733
- assert_approx_eq ! ( 1.0f128 . gamma( ) , 1.0f128 , TOL_IMPR ) ;
734
- assert_approx_eq ! ( 2.0f128 . gamma( ) , 1.0f128 , TOL_IMPR ) ;
735
- assert_approx_eq ! ( 3.0f128 . gamma( ) , 2.0f128 , TOL_IMPR ) ;
736
- assert_approx_eq ! ( 4.0f128 . gamma( ) , 6.0f128 , TOL_IMPR ) ;
737
- assert_approx_eq ! ( 5.0f128 . gamma( ) , 24.0f128 , TOL_IMPR ) ;
738
- assert_approx_eq ! ( 0.5f128 . gamma( ) , consts:: PI . sqrt( ) , TOL_IMPR ) ;
739
- assert_approx_eq ! ( ( -0.5f128 ) . gamma( ) , -2.0 * consts:: PI . sqrt( ) , TOL_IMPR ) ;
740
- assert_eq ! ( 0.0f128 . gamma( ) , f128:: INFINITY ) ;
741
- assert_eq ! ( ( -0.0f128 ) . gamma( ) , f128:: NEG_INFINITY ) ;
742
- assert ! ( ( -1.0f128 ) . gamma( ) . is_nan( ) ) ;
743
- assert ! ( ( -2.0f128 ) . gamma( ) . is_nan( ) ) ;
744
- assert ! ( f128:: NAN . gamma( ) . is_nan( ) ) ;
745
- assert ! ( f128:: NEG_INFINITY . gamma( ) . is_nan( ) ) ;
746
- assert_eq ! ( f128:: INFINITY . gamma( ) , f128:: INFINITY ) ;
747
- assert_eq ! ( 1760.9f128 . gamma( ) , f128:: INFINITY ) ;
748
- }
749
-
750
- #[ test]
751
- #[ cfg( reliable_f128_math) ]
752
- fn test_ln_gamma ( ) {
753
- assert_approx_eq ! ( 1.0f128 . ln_gamma( ) . 0 , 0.0f128 , TOL_IMPR ) ;
754
- assert_eq ! ( 1.0f128 . ln_gamma( ) . 1 , 1 ) ;
755
- assert_approx_eq ! ( 2.0f128 . ln_gamma( ) . 0 , 0.0f128 , TOL_IMPR ) ;
756
- assert_eq ! ( 2.0f128 . ln_gamma( ) . 1 , 1 ) ;
757
- assert_approx_eq ! ( 3.0f128 . ln_gamma( ) . 0 , 2.0f128 . ln( ) , TOL_IMPR ) ;
758
- assert_eq ! ( 3.0f128 . ln_gamma( ) . 1 , 1 ) ;
759
- assert_approx_eq ! ( ( -0.5f128 ) . ln_gamma( ) . 0 , ( 2.0 * consts:: PI . sqrt( ) ) . ln( ) , TOL_IMPR ) ;
760
- assert_eq ! ( ( -0.5f128 ) . ln_gamma( ) . 1 , -1 ) ;
761
- }
762
-
763
- #[ test]
764
- fn test_real_consts ( ) {
765
- let pi: f128 = consts:: PI ;
766
- let frac_pi_2: f128 = consts:: FRAC_PI_2 ;
767
- let frac_pi_3: f128 = consts:: FRAC_PI_3 ;
768
- let frac_pi_4: f128 = consts:: FRAC_PI_4 ;
769
- let frac_pi_6: f128 = consts:: FRAC_PI_6 ;
770
- let frac_pi_8: f128 = consts:: FRAC_PI_8 ;
771
- let frac_1_pi: f128 = consts:: FRAC_1_PI ;
772
- let frac_2_pi: f128 = consts:: FRAC_2_PI ;
773
-
774
- assert_approx_eq ! ( frac_pi_2, pi / 2 f128, TOL_PRECISE ) ;
775
- assert_approx_eq ! ( frac_pi_3, pi / 3 f128, TOL_PRECISE ) ;
776
- assert_approx_eq ! ( frac_pi_4, pi / 4 f128, TOL_PRECISE ) ;
777
- assert_approx_eq ! ( frac_pi_6, pi / 6 f128, TOL_PRECISE ) ;
778
- assert_approx_eq ! ( frac_pi_8, pi / 8 f128, TOL_PRECISE ) ;
779
- assert_approx_eq ! ( frac_1_pi, 1 f128 / pi, TOL_PRECISE ) ;
780
- assert_approx_eq ! ( frac_2_pi, 2 f128 / pi, TOL_PRECISE ) ;
781
-
782
- #[ cfg( reliable_f128_math) ]
783
- {
784
- let frac_2_sqrtpi: f128 = consts:: FRAC_2_SQRT_PI ;
785
- let sqrt2: f128 = consts:: SQRT_2 ;
786
- let frac_1_sqrt2: f128 = consts:: FRAC_1_SQRT_2 ;
787
- let e: f128 = consts:: E ;
788
- let log2_e: f128 = consts:: LOG2_E ;
789
- let log10_e: f128 = consts:: LOG10_E ;
790
- let ln_2: f128 = consts:: LN_2 ;
791
- let ln_10: f128 = consts:: LN_10 ;
792
-
793
- assert_approx_eq ! ( frac_2_sqrtpi, 2 f128 / pi. sqrt( ) , TOL_PRECISE ) ;
794
- assert_approx_eq ! ( sqrt2, 2 f128. sqrt( ) , TOL_PRECISE ) ;
795
- assert_approx_eq ! ( frac_1_sqrt2, 1 f128 / 2 f128. sqrt( ) , TOL_PRECISE ) ;
796
- assert_approx_eq ! ( log2_e, e. log2( ) , TOL_PRECISE ) ;
797
- assert_approx_eq ! ( log10_e, e. log10( ) , TOL_PRECISE ) ;
798
- assert_approx_eq ! ( ln_2, 2 f128. ln( ) , TOL_PRECISE ) ;
799
- assert_approx_eq ! ( ln_10, 10 f128. ln( ) , TOL_PRECISE ) ;
800
- }
801
- }
802
-
803
536
#[ test]
804
537
fn test_float_bits_conv ( ) {
805
538
assert_eq ! ( ( 1 f128) . to_bits( ) , 0x3fff0000000000000000000000000000 ) ;
0 commit comments