Skip to content

Commit 919292f

Browse files
committed
bit test
1 parent 8e3af52 commit 919292f

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/gamma.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,9 @@ mod tests {
298298
let Some((py_gamma, rs_gamma)) = unwrap(py, r, rs_gamma) else {
299299
return;
300300
};
301-
let py_gamma_repr = unsafe { std::mem::transmute::<f64, i64>(py_gamma) };
302-
let rs_gamma_repr = unsafe { std::mem::transmute::<f64, i64>(rs_gamma) };
303-
// assert_eq!(py_gamma_repr, rs_gamma_repr, "x = {x}, py_gamma = {py_gamma}, rs_gamma = {rs_gamma}");
304-
// allow 1 bit error for now
305-
assert!((py_gamma_repr - rs_gamma_repr).abs() <= 1, "x = {x} diff: {}, py_gamma = {py_gamma} ({py_gamma_repr:x}), rs_gamma = {rs_gamma} ({rs_gamma_repr:x})", py_gamma_repr ^ rs_gamma_repr);
301+
let py_gamma_repr = py_gamma.to_bits();
302+
let rs_gamma_repr = rs_gamma.to_bits();
303+
assert_eq!(py_gamma_repr, rs_gamma_repr, "x = {x}, py_gamma = {py_gamma}, rs_gamma = {rs_gamma}");
306304
});
307305
}
308306

@@ -312,18 +310,17 @@ mod tests {
312310

313311
pyo3::prepare_freethreaded_python();
314312
Python::with_gil(|py| {
315-
let math = PyModule::import(py, "math").unwrap();
316-
let py_lgamma_func = math
317-
.getattr("lgamma")
318-
.unwrap();
319-
let r = py_lgamma_func.call1((x,));
320-
let Some((py_lgamma, rs_lgamma)) = unwrap(py, r, rs_lgamma) else {
321-
return;
322-
};
323-
let py_lgamma_repr = unsafe { std::mem::transmute::<f64, i64>(py_lgamma) };
324-
let rs_lgamma_repr = unsafe { std::mem::transmute::<f64, i64>(rs_lgamma) };
325-
// allow 6 bit error for now
326-
assert!((py_lgamma_repr - rs_lgamma_repr).abs() <= 6, "x = {x} diff: {}, py_lgamma = {py_lgamma} ({py_lgamma_repr:x}), rs_lgamma = {rs_lgamma} ({rs_lgamma_repr:x})", py_lgamma_repr ^ rs_lgamma_repr);
313+
let math = PyModule::import(py, "math").unwrap();
314+
let py_lgamma_func = math
315+
.getattr("lgamma")
316+
.unwrap();
317+
let r = py_lgamma_func.call1((x,));
318+
let Some((py_lgamma, rs_lgamma)) = unwrap(py, r, rs_lgamma) else {
319+
return;
320+
};
321+
let py_lgamma_repr = py_lgamma.to_bits();
322+
let rs_lgamma_repr = rs_lgamma.to_bits();
323+
assert_eq!(py_lgamma_repr, rs_lgamma_repr, "x = {x}, py_lgamma = {py_lgamma}, rs_gamma = {rs_lgamma}");
327324
});
328325
}
329326
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ mod err;
22
mod gamma;
33

44
pub use err::Error;
5-
pub use gamma::{tgamma as gamma, lgamma};
5+
pub use gamma::{lgamma, tgamma as gamma};

0 commit comments

Comments
 (0)