Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0bca7c3

Browse files
committed
Adjust more tests; locally (aarch) only test_powi fails
1 parent0f373a5 commit0bca7c3

File tree

3 files changed

+69
-77
lines changed

3 files changed

+69
-77
lines changed

‎library/std/src/f128/tests.rs‎

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
usecrate::f128::consts;
66
usecrate::num::*;
77

8-
/// Tolerance for results on the order of 10.0e-4;
9-
constTOL_N4:f16 =1e-42;
10-
118
/// Tolerance for results on the order of 10.0e-2;
129
constTOL_N2:f128 =1e-32;
1310

@@ -255,16 +252,16 @@ fn test_trunc() {
255252

256253
#[test]
257254
fntest_fract(){
258-
assert_approx_eq!(1.0f128.fract(),0.0f128,TOL_N2);
259-
assert_approx_eq!(1.3f128.fract(),0.3f128,TOL_N2);
260-
assert_approx_eq!(1.5f128.fract(),0.5f128,TOL_N2);
261-
assert_approx_eq!(1.7f128.fract(),0.7f128,TOL_N2);
262-
assert_approx_eq!(0.0f128.fract(),0.0f128,TOL_N2);
263-
assert_approx_eq!((-0.0f128).fract(), -0.0f128,TOL_N2);
264-
assert_approx_eq!((-1.0f128).fract(), -0.0f128,TOL_N2);
265-
assert_approx_eq!((-1.3f128).fract(), -0.3f128,TOL_N2);
266-
assert_approx_eq!((-1.5f128).fract(), -0.5f128,TOL_N2);
267-
assert_approx_eq!((-1.7f128).fract(), -0.7f128,TOL_N2);
255+
assert_approx_eq!(1.0f128.fract(),0.0f128,TOL_0);
256+
assert_approx_eq!(1.3f128.fract(),0.3f128,TOL_0);
257+
assert_approx_eq!(1.5f128.fract(),0.5f128,TOL_0);
258+
assert_approx_eq!(1.7f128.fract(),0.7f128,TOL_0);
259+
assert_approx_eq!(0.0f128.fract(),0.0f128,TOL_0);
260+
assert_approx_eq!((-0.0f128).fract(), -0.0f128,TOL_0);
261+
assert_approx_eq!((-1.0f128).fract(), -0.0f128,TOL_0);
262+
assert_approx_eq!((-1.3f128).fract(), -0.3f128,TOL_0);
263+
assert_approx_eq!((-1.5f128).fract(), -0.5f128,TOL_0);
264+
assert_approx_eq!((-1.7f128).fract(), -0.7f128,TOL_0);
268265
}
269266

270267
#[test]
@@ -408,7 +405,7 @@ fn test_powi() {
408405
let neg_inf:f128 = f128::NEG_INFINITY;
409406
assert_eq!(1.0f128.powi(1),1.0);
410407
assert_approx_eq!((-3.1f128).powi(2),9.61,TOL_0);
411-
assert_approx_eq!(5.9f128.powi(-2),0.028727,TOL_N4);
408+
assert_approx_eq!(5.9f128.powi(-2),0.028727,TOL_N2);
412409
assert_eq!(8.3f128.powi(0),1.0);
413410
assert!(nan.powi(2).is_nan());
414411
assert_eq!(inf.powi(3), inf);
@@ -422,9 +419,9 @@ fn test_powf() {
422419
let neg_inf:f128 = f128::NEG_INFINITY;
423420
assert_eq!(1.0f128.powf(1.0),1.0);
424421
assert_approx_eq!(3.4f128.powf(4.5),246.408183,TOL_P2);
425-
assert_approx_eq!(2.7f128.powf(-3.2),0.041652,TOL_N4);
422+
assert_approx_eq!(2.7f128.powf(-3.2),0.041652,TOL_N2);
426423
assert_approx_eq!((-3.1f128).powf(2.0),9.61,TOL_P2);
427-
assert_approx_eq!(5.9f128.powf(-2.0),0.028727,TOL_N4);
424+
assert_approx_eq!(5.9f128.powf(-2.0),0.028727,TOL_N2);
428425
assert_eq!(8.3f128.powf(0.0),1.0);
429426
assert!(nan.powf(2.0).is_nan());
430427
assert_eq!(inf.powf(2.0), inf);
@@ -490,7 +487,7 @@ fn test_log() {
490487
let inf:f128 = f128::INFINITY;
491488
let neg_inf:f128 = f128::NEG_INFINITY;
492489
assert_eq!(10.0f128.log(10.0),1.0);
493-
assert_approx_eq!(2.3f128.log(3.5),0.664858,TOL_N2);
490+
assert_approx_eq!(2.3f128.log(3.5),0.664858,TOL_0);
494491
assert_eq!(1.0f128.exp().log(1.0f128.exp()),1.0);
495492
assert!(1.0f128.log(1.0).is_nan());
496493
assert!(1.0f128.log(-13.9).is_nan());
@@ -524,8 +521,8 @@ fn test_log10() {
524521
let inf:f128 = f128::INFINITY;
525522
let neg_inf:f128 = f128::NEG_INFINITY;
526523
assert_eq!(10.0f128.log10(),1.0);
527-
assert_approx_eq!(2.3f128.log10(),0.361728,TOL_N2);
528-
assert_approx_eq!(1.0f128.exp().log10(),0.434294,TOL_N2);
524+
assert_approx_eq!(2.3f128.log10(),0.361728,TOL_0);
525+
assert_approx_eq!(1.0f128.exp().log10(),0.434294,TOL_0);
529526
assert_eq!(1.0f128.log10(),0.0);
530527
assert!(nan.log10().is_nan());
531528
assert_eq!(inf.log10(), inf);
@@ -610,7 +607,7 @@ fn test_acosh() {
610607
assert_approx_eq!(3.0f128.acosh(),1.76274717403908605046521864995958461f128,TOL_0);
611608

612609
// test for low accuracy from issue 104548
613-
assert_approx_eq!(60.0f128,60.0f128.cosh().acosh());
610+
assert_approx_eq!(60.0f128,60.0f128.cosh().acosh(),TOL_P2);
614611
}
615612

616613
#[test]
@@ -628,8 +625,8 @@ fn test_atanh() {
628625
assert!(inf.atanh().is_nan());
629626
assert!(neg_inf.atanh().is_nan());
630627
assert!(nan.atanh().is_nan());
631-
assert_approx_eq!(0.5f128.atanh(),0.54930614433405484569762261846126285f128,TOL_N2);
632-
assert_approx_eq!((-0.5f128).atanh(), -0.54930614433405484569762261846126285f128,TOL_N2);
628+
assert_approx_eq!(0.5f128.atanh(),0.54930614433405484569762261846126285f128,TOL_0);
629+
assert_approx_eq!((-0.5f128).atanh(), -0.54930614433405484569762261846126285f128,TOL_0);
633630
}
634631

635632
#[test]
@@ -685,20 +682,20 @@ fn test_real_consts() {
685682
let ln_2:f128 = consts::LN_2;
686683
let ln_10:f128 = consts::LN_10;
687684

688-
assert_approx_eq!(frac_pi_2, pi /2f128,TOL_N2);
689-
assert_approx_eq!(frac_pi_3, pi /3f128,TOL_N2);
690-
assert_approx_eq!(frac_pi_4, pi /4f128,TOL_N2);
691-
assert_approx_eq!(frac_pi_6, pi /6f128,TOL_N2);
692-
assert_approx_eq!(frac_pi_8, pi /8f128,TOL_N2);
693-
assert_approx_eq!(frac_1_pi,1f128 / pi,TOL_N2);
694-
assert_approx_eq!(frac_2_pi,2f128 / pi,TOL_N2);
695-
assert_approx_eq!(frac_2_sqrtpi,2f128 / pi.sqrt(),TOL_N2);
696-
assert_approx_eq!(sqrt2,2f128.sqrt(),TOL_N2);
697-
assert_approx_eq!(frac_1_sqrt2,1f128 /2f128.sqrt(),TOL_N2);
698-
assert_approx_eq!(log2_e, e.log2(),TOL_N2);
699-
assert_approx_eq!(log10_e, e.log10(),TOL_N2);
700-
assert_approx_eq!(ln_2,2f128.ln(),TOL_N2);
701-
assert_approx_eq!(ln_10,10f128.ln(),TOL_N2);
685+
assert_approx_eq!(frac_pi_2, pi /2f128,TOL_0);
686+
assert_approx_eq!(frac_pi_3, pi /3f128,TOL_0);
687+
assert_approx_eq!(frac_pi_4, pi /4f128,TOL_0);
688+
assert_approx_eq!(frac_pi_6, pi /6f128,TOL_0);
689+
assert_approx_eq!(frac_pi_8, pi /8f128,TOL_0);
690+
assert_approx_eq!(frac_1_pi,1f128 / pi,TOL_0);
691+
assert_approx_eq!(frac_2_pi,2f128 / pi,TOL_0);
692+
assert_approx_eq!(frac_2_sqrtpi,2f128 / pi.sqrt(),TOL_0);
693+
assert_approx_eq!(sqrt2,2f128.sqrt(),TOL_0);
694+
assert_approx_eq!(frac_1_sqrt2,1f128 /2f128.sqrt(),TOL_0);
695+
assert_approx_eq!(log2_e, e.log2(),TOL_0);
696+
assert_approx_eq!(log10_e, e.log10(),TOL_0);
697+
assert_approx_eq!(ln_2,2f128.ln(),TOL_0);
698+
assert_approx_eq!(ln_10,10f128.ln(),TOL_0);
702699
}
703700

704701
#[test]

‎library/std/src/f16/tests.rs‎

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
usecrate::f16::consts;
66
usecrate::num::*;
77

8-
// We run out of precision pretty quickly with f16
9-
10-
/// Tolerance for results on the order of 10.0e-4;
11-
constTOL_N4:f16 =1e-5;
12-
138
/// Tolerance for results on the order of 10.0e-2;
149
constTOL_N2:f16 =0.0001;
1510

@@ -257,16 +252,16 @@ fn test_trunc() {
257252

258253
#[test]
259254
fntest_fract(){
260-
assert_approx_eq!(1.0f16.fract(),0.0f16,TOL_N2);
261-
assert_approx_eq!(1.3f16.fract(),0.3f16,TOL_N2);
262-
assert_approx_eq!(1.5f16.fract(),0.5f16,TOL_N2);
263-
assert_approx_eq!(1.7f16.fract(),0.7f16,TOL_N2);
264-
assert_approx_eq!(0.0f16.fract(),0.0f16,TOL_N2);
265-
assert_approx_eq!((-0.0f16).fract(), -0.0f16,TOL_N2);
266-
assert_approx_eq!((-1.0f16).fract(), -0.0f16,TOL_N2);
267-
assert_approx_eq!((-1.3f16).fract(), -0.3f16,TOL_N2);
268-
assert_approx_eq!((-1.5f16).fract(), -0.5f16,TOL_N2);
269-
assert_approx_eq!((-1.7f16).fract(), -0.7f16,TOL_N2);
255+
assert_approx_eq!(1.0f16.fract(),0.0f16,TOL_0);
256+
assert_approx_eq!(1.3f16.fract(),0.3f16,TOL_0);
257+
assert_approx_eq!(1.5f16.fract(),0.5f16,TOL_0);
258+
assert_approx_eq!(1.7f16.fract(),0.7f16,TOL_0);
259+
assert_approx_eq!(0.0f16.fract(),0.0f16,TOL_0);
260+
assert_approx_eq!((-0.0f16).fract(), -0.0f16,TOL_0);
261+
assert_approx_eq!((-1.0f16).fract(), -0.0f16,TOL_0);
262+
assert_approx_eq!((-1.3f16).fract(), -0.3f16,TOL_0);
263+
assert_approx_eq!((-1.5f16).fract(), -0.5f16,TOL_0);
264+
assert_approx_eq!((-1.7f16).fract(), -0.7f16,TOL_0);
270265
}
271266

272267
#[test]
@@ -406,7 +401,7 @@ fn test_powi() {
406401
let neg_inf:f16 = f16::NEG_INFINITY;
407402
assert_eq!(1.0f16.powi(1),1.0);
408403
assert_approx_eq!((-3.1f16).powi(2),9.61,TOL_0);
409-
assert_approx_eq!(5.9f16.powi(-2),0.028727,TOL_N4);
404+
assert_approx_eq!(5.9f16.powi(-2),0.028727,TOL_N2);
410405
assert_eq!(8.3f16.powi(0),1.0);
411406
assert!(nan.powi(2).is_nan());
412407
assert_eq!(inf.powi(3), inf);
@@ -420,9 +415,9 @@ fn test_powf() {
420415
let neg_inf:f16 = f16::NEG_INFINITY;
421416
assert_eq!(1.0f16.powf(1.0),1.0);
422417
assert_approx_eq!(3.4f16.powf(4.5),246.408183,TOL_P2);
423-
assert_approx_eq!(2.7f16.powf(-3.2),0.041652,TOL_N4);
418+
assert_approx_eq!(2.7f16.powf(-3.2),0.041652,TOL_N2);
424419
assert_approx_eq!((-3.1f16).powf(2.0),9.61,TOL_P2);
425-
assert_approx_eq!(5.9f16.powf(-2.0),0.028727,TOL_N4);
420+
assert_approx_eq!(5.9f16.powf(-2.0),0.028727,TOL_N2);
426421
assert_eq!(8.3f16.powf(0.0),1.0);
427422
assert!(nan.powf(2.0).is_nan());
428423
assert_eq!(inf.powf(2.0), inf);
@@ -488,7 +483,7 @@ fn test_log() {
488483
let inf:f16 = f16::INFINITY;
489484
let neg_inf:f16 = f16::NEG_INFINITY;
490485
assert_eq!(10.0f16.log(10.0),1.0);
491-
assert_approx_eq!(2.3f16.log(3.5),0.664858,TOL_N2);
486+
assert_approx_eq!(2.3f16.log(3.5),0.664858,TOL_0);
492487
assert_eq!(1.0f16.exp().log(1.0f16.exp()),1.0);
493488
assert!(1.0f16.log(1.0).is_nan());
494489
assert!(1.0f16.log(-13.9).is_nan());
@@ -522,8 +517,8 @@ fn test_log10() {
522517
let inf:f16 = f16::INFINITY;
523518
let neg_inf:f16 = f16::NEG_INFINITY;
524519
assert_eq!(10.0f16.log10(),1.0);
525-
assert_approx_eq!(2.3f16.log10(),0.361728,TOL_N2);
526-
assert_approx_eq!(1.0f16.exp().log10(),0.434294,TOL_N2);
520+
assert_approx_eq!(2.3f16.log10(),0.361728,TOL_0);
521+
assert_approx_eq!(1.0f16.exp().log10(),0.434294,TOL_0);
527522
assert_eq!(1.0f16.log10(),0.0);
528523
assert!(nan.log10().is_nan());
529524
assert_eq!(inf.log10(), inf);
@@ -582,9 +577,9 @@ fn test_asinh() {
582577
assert_approx_eq!((-200.0f16).asinh(), -5.991470797049389,TOL_0);
583578

584579
// test for low accuracy from issue 104548
585-
assert_approx_eq!(60.0f16,60.0f16.sinh().asinh(),TOL_0);
580+
assert_approx_eq!(10.0f16,10.0f16.sinh().asinh(),TOL_0);
586581
// mul needed for approximate comparison to be meaningful
587-
assert_approx_eq!(1.0f16,1e-15f16.sinh().asinh()*1e15f16,TOL_0);
582+
assert_approx_eq!(1.0f16,1e-3f16.sinh().asinh()*1e3f16,TOL_0);
588583
}
589584

590585
#[test]
@@ -602,7 +597,7 @@ fn test_acosh() {
602597
assert_approx_eq!(3.0f16.acosh(),1.76274717403908605046521864995958461f16,TOL_0);
603598

604599
// test for low accuracy from issue 104548
605-
assert_approx_eq!(60.0f16,60.0f16.cosh().acosh());
600+
assert_approx_eq!(10.0f16,10.0f16.cosh().acosh(),TOL_P2);
606601
}
607602

608603
#[test]
@@ -620,8 +615,8 @@ fn test_atanh() {
620615
assert!(inf.atanh().is_nan());
621616
assert!(neg_inf.atanh().is_nan());
622617
assert!(nan.atanh().is_nan());
623-
assert_approx_eq!(0.5f16.atanh(),0.54930614433405484569762261846126285f16,TOL_N2);
624-
assert_approx_eq!((-0.5f16).atanh(), -0.54930614433405484569762261846126285f16,TOL_N2);
618+
assert_approx_eq!(0.5f16.atanh(),0.54930614433405484569762261846126285f16,TOL_0);
619+
assert_approx_eq!((-0.5f16).atanh(), -0.54930614433405484569762261846126285f16,TOL_0);
625620
}
626621

627622
#[test]
@@ -678,20 +673,20 @@ fn test_real_consts() {
678673
let ln_2:f16 = consts::LN_2;
679674
let ln_10:f16 = consts::LN_10;
680675

681-
assert_approx_eq!(frac_pi_2, pi /2f16,TOL_N2);
682-
assert_approx_eq!(frac_pi_3, pi /3f16,TOL_N2);
683-
assert_approx_eq!(frac_pi_4, pi /4f16,TOL_N2);
684-
assert_approx_eq!(frac_pi_6, pi /6f16,TOL_N2);
685-
assert_approx_eq!(frac_pi_8, pi /8f16,TOL_N2);
686-
assert_approx_eq!(frac_1_pi,1f16 / pi,TOL_N2);
687-
assert_approx_eq!(frac_2_pi,2f16 / pi,TOL_N2);
688-
assert_approx_eq!(frac_2_sqrtpi,2f16 / pi.sqrt(),TOL_N2);
689-
assert_approx_eq!(sqrt2,2f16.sqrt(),TOL_N2);
690-
assert_approx_eq!(frac_1_sqrt2,1f16 /2f16.sqrt(),TOL_N2);
691-
assert_approx_eq!(log2_e, e.log2(),TOL_N2);
692-
assert_approx_eq!(log10_e, e.log10(),TOL_N2);
693-
assert_approx_eq!(ln_2,2f16.ln(),TOL_N2);
694-
assert_approx_eq!(ln_10,10f16.ln(),TOL_N2);
676+
assert_approx_eq!(frac_pi_2, pi /2f16,TOL_0);
677+
assert_approx_eq!(frac_pi_3, pi /3f16,TOL_0);
678+
assert_approx_eq!(frac_pi_4, pi /4f16,TOL_0);
679+
assert_approx_eq!(frac_pi_6, pi /6f16,TOL_0);
680+
assert_approx_eq!(frac_pi_8, pi /8f16,TOL_0);
681+
assert_approx_eq!(frac_1_pi,1f16 / pi,TOL_0);
682+
assert_approx_eq!(frac_2_pi,2f16 / pi,TOL_0);
683+
assert_approx_eq!(frac_2_sqrtpi,2f16 / pi.sqrt(),TOL_0);
684+
assert_approx_eq!(sqrt2,2f16.sqrt(),TOL_0);
685+
assert_approx_eq!(frac_1_sqrt2,1f16 /2f16.sqrt(),TOL_0);
686+
assert_approx_eq!(log2_e, e.log2(),TOL_0);
687+
assert_approx_eq!(log10_e, e.log10(),TOL_0);
688+
assert_approx_eq!(ln_2,2f16.ln(),TOL_0);
689+
assert_approx_eq!(ln_10,10f16.ln(),TOL_0);
695690
}
696691

697692
#[test]

‎library/std/src/macros.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ macro_rules! assert_approx_eq {
382382
let diff =(*a -*b).abs();
383383
assert!(
384384
diff < $lim,
385-
"{a:?} is not approximately equal to {b:?} (threshold {lim:?},actual {diff:?})",
385+
"{a:?} is not approximately equal to {b:?} (threshold {lim:?},difference {diff:?})",
386386
lim = $lim
387387
);
388388
}};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp