Skip to content

Commit ed06877

Browse files
committed
add test
1 parent 8ebaf63 commit ed06877

File tree

1 file changed

+29
-0
lines changed
  • library/coretests/tests/floats

1 file changed

+29
-0
lines changed

library/coretests/tests/floats/f16.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,35 @@ fn test_mul_add() {
4848
assert_biteq!((-3.2f16).mul_add(2.4, neg_inf), neg_inf);
4949
}
5050

51+
fn to_radians_expr(degs: f16) -> f16 {
52+
degs * 0.017453292519943295769236907684886_f16
53+
}
54+
55+
fn to_radians_const(degs: f16) -> f16 {
56+
let factor = 0.017453292519943295769236907684886_f16;
57+
degs * factor
58+
}
59+
60+
#[test]
61+
#[cfg(any(miri, target_has_reliable_f16_math))]
62+
fn expression_has_same_precision_as_constant() {
63+
fn assert_the_same(val: f16) {
64+
assert_biteq!(to_radians_expr(val), to_radians_const(val));
65+
}
66+
assert_the_same(-0.0001);
67+
assert_the_same(0.0);
68+
assert_the_same(1.0);
69+
assert_the_same(90.0);
70+
assert_the_same(180.0);
71+
assert_the_same(360.0);
72+
assert_the_same(-360.0);
73+
assert_the_same(f16::MAX);
74+
assert_the_same(f16::MIN);
75+
assert_the_same(f16::NAN);
76+
assert_the_same(f16::INFINITY);
77+
assert_the_same(f16::NEG_INFINITY);
78+
}
79+
5180
#[test]
5281
#[cfg(any(miri, target_has_reliable_f16_math))]
5382
fn test_recip() {

0 commit comments

Comments
 (0)