Skip to content

Commit b4d3d07

Browse files
committed
Move applicable float tests from coretests back to std
The previous commit moved all test files from `std` to `core` so git understands the move. Not all functionality is actually testable in `core`, however, so perform move the relevant portions back. Changes from inherent to module methods is also done since this is the form of math operations available in `core` (as `core_float_math`).
1 parent b502d03 commit b4d3d07

File tree

13 files changed

+1352
-1202
lines changed

13 files changed

+1352
-1202
lines changed

compiler/rustc_codegen_cranelift/patches/0027-sysroot_tests-128bit-atomic-operations.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ index 1e336bf..35e6f54 100644
1616
+++ b/coretests/tests/lib.rs
1717
@@ -2,5 +2,4 @@
1818
// tidy-alphabetical-start
19+
#![cfg_attr(not(bootstrap), feature(cfg_target_has_reliable_f16_f128))]
1920
-#![cfg_attr(target_has_atomic = "128", feature(integer_atomics))]
2021
#![cfg_attr(test, feature(cfg_match))]
2122
#![feature(alloc_layout_extra)]
22-
#![feature(array_chunks)]
2323
diff --git a/coretests/tests/atomic.rs b/coretests/tests/atomic.rs
2424
index b735957..ea728b6 100644
2525
--- a/coretests/tests/atomic.rs

library/coretests/build.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mod build_shared {
2+
include!("../std/build_shared.rs");
3+
}
4+
5+
fn main() {
6+
println!("cargo:rerun-if-changed=../std/build_shared.rs");
7+
8+
let cfg = build_shared::Config::from_env();
9+
build_shared::configure_f16_f128(&cfg);
10+
}

library/coretests/tests/floats/f128.rs

+3-298
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,13 @@ use std::ops::{Add, Div, Mul, Sub};
1212

1313
// Note these tolerances make sense around zero, but not for more extreme exponents.
1414

15-
/// For operations that are near exact, usually not involving math of different
16-
/// signs.
17-
const TOL_PRECISE: f128 = 1e-28;
18-
1915
/// Default tolerances. Works for values that should be near precise but not exact. Roughly
2016
/// the precision carried by `100 * 100`.
2117
const TOL: f128 = 1e-12;
2218

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;
2922

3023
/// Smallest number
3124
const TINY_BITS: u128 = 0x1;
@@ -517,8 +510,6 @@ fn test_recip() {
517510
assert_eq!(neg_inf.recip(), 0.0);
518511
}
519512

520-
// Many math functions allow for less accurate results, so the next tolerance up is used
521-
522513
#[test]
523514
#[cfg(not(miri))]
524515
#[cfg(not(bootstrap))]
@@ -536,25 +527,6 @@ fn test_powi() {
536527
assert_eq!(neg_inf.powi(2), inf);
537528
}
538529

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-
558530
#[test]
559531
#[cfg(not(miri))]
560532
#[cfg(not(bootstrap))]
@@ -569,117 +541,6 @@ fn test_sqrt_domain() {
569541
assert_eq!(f128::INFINITY.sqrt(), f128::INFINITY);
570542
}
571543

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-
683544
#[test]
684545
fn test_to_degrees() {
685546
let pi: f128 = consts::PI;
@@ -712,162 +573,6 @@ fn test_to_radians() {
712573
assert_eq!(neg_inf.to_radians(), neg_inf);
713574
}
714575

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!(2f128.atanh().atanh().is_nan());
783-
assert!((-2f128).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 / 2f128, TOL_PRECISE);
841-
assert_approx_eq!(frac_pi_3, pi / 3f128, TOL_PRECISE);
842-
assert_approx_eq!(frac_pi_4, pi / 4f128, TOL_PRECISE);
843-
assert_approx_eq!(frac_pi_6, pi / 6f128, TOL_PRECISE);
844-
assert_approx_eq!(frac_pi_8, pi / 8f128, TOL_PRECISE);
845-
assert_approx_eq!(frac_1_pi, 1f128 / pi, TOL_PRECISE);
846-
assert_approx_eq!(frac_2_pi, 2f128 / 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, 2f128 / pi.sqrt(), TOL_PRECISE);
862-
assert_approx_eq!(sqrt2, 2f128.sqrt(), TOL_PRECISE);
863-
assert_approx_eq!(frac_1_sqrt2, 1f128 / 2f128.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, 2f128.ln(), TOL_PRECISE);
867-
assert_approx_eq!(ln_10, 10f128.ln(), TOL_PRECISE);
868-
}
869-
}
870-
871576
#[test]
872577
fn test_float_bits_conv() {
873578
assert_eq!((1f128).to_bits(), 0x3fff0000000000000000000000000000);

0 commit comments

Comments
 (0)