Skip to content

Commit 5d5e2a2

Browse files
committed
Move float_pow tests to their own file
1 parent d50b093 commit 5d5e2a2

File tree

2 files changed

+54
-56
lines changed

2 files changed

+54
-56
lines changed

testcrate/tests/float_pow.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#![allow(unused_macros)]
2+
#![cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
3+
4+
use testcrate::*;
5+
6+
// This is approximate because of issues related to
7+
// https://github.com/rust-lang/rust/issues/73920.
8+
// TODO how do we resolve this indeterminacy?
9+
macro_rules! pow {
10+
($($f:ty, $tolerance:expr, $fn:ident);*;) => {
11+
$(
12+
#[test]
13+
fn $fn() {
14+
use compiler_builtins::float::pow::$fn;
15+
use compiler_builtins::float::Float;
16+
fuzz_float_2(N, |x: $f, y: $f| {
17+
if !(Float::is_subnormal(x) || Float::is_subnormal(y) || x.is_nan()) {
18+
let n = y.to_bits() & !<$f as Float>::SIGNIFICAND_MASK;
19+
let n = (n as <$f as Float>::SignedInt) >> <$f as Float>::SIGNIFICAND_BITS;
20+
let n = n as i32;
21+
let tmp0: $f = x.powi(n);
22+
let tmp1: $f = $fn(x, n);
23+
let (a, b) = if tmp0 < tmp1 {
24+
(tmp0, tmp1)
25+
} else {
26+
(tmp1, tmp0)
27+
};
28+
29+
let good = if a == b {
30+
// handles infinity equality
31+
true
32+
} else if a < $tolerance {
33+
b < $tolerance
34+
} else {
35+
let quo = b / a;
36+
(quo < (1. + $tolerance)) && (quo > (1. - $tolerance))
37+
};
38+
39+
assert!(
40+
good,
41+
"{}({:?}, {:?}): std: {:?}, builtins: {:?}",
42+
stringify!($fn), x, n, tmp0, tmp1
43+
);
44+
}
45+
});
46+
}
47+
)*
48+
};
49+
}
50+
51+
pow! {
52+
f32, 1e-4, __powisf2;
53+
f64, 1e-12, __powidf2;
54+
}

testcrate/tests/misc.rs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -207,59 +207,3 @@ fn bswap() {
207207
);
208208
}
209209
}
210-
211-
// This is approximate because of issues related to
212-
// https://github.com/rust-lang/rust/issues/73920.
213-
// TODO how do we resolve this indeterminacy?
214-
macro_rules! pow {
215-
($($f:ty, $tolerance:expr, $fn:ident);*;) => {
216-
$(
217-
#[test]
218-
fn $fn() {
219-
use compiler_builtins::float::pow::$fn;
220-
use compiler_builtins::float::Float;
221-
fuzz_float_2(N, |x: $f, y: $f| {
222-
if !(Float::is_subnormal(x) || Float::is_subnormal(y) || x.is_nan()) {
223-
let n = y.to_bits() & !<$f as Float>::SIGNIFICAND_MASK;
224-
let n = (n as <$f as Float>::SignedInt) >> <$f as Float>::SIGNIFICAND_BITS;
225-
let n = n as i32;
226-
let tmp0: $f = x.powi(n);
227-
let tmp1: $f = $fn(x, n);
228-
let (a, b) = if tmp0 < tmp1 {
229-
(tmp0, tmp1)
230-
} else {
231-
(tmp1, tmp0)
232-
};
233-
let good = {
234-
if a == b {
235-
// handles infinity equality
236-
true
237-
} else if a < $tolerance {
238-
b < $tolerance
239-
} else {
240-
let quo = b / a;
241-
(quo < (1. + $tolerance)) && (quo > (1. - $tolerance))
242-
}
243-
};
244-
if !good {
245-
panic!(
246-
"{}({}, {}): std: {}, builtins: {}",
247-
stringify!($fn), x, n, tmp0, tmp1
248-
);
249-
}
250-
}
251-
});
252-
}
253-
)*
254-
};
255-
}
256-
257-
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse"))))]
258-
mod float_pow {
259-
use super::*;
260-
261-
pow! {
262-
f32, 1e-4, __powisf2;
263-
f64, 1e-12, __powidf2;
264-
}
265-
}

0 commit comments

Comments
 (0)