commonlibsse_ng\macros/
assert.rs1#[macro_export]
7#[doc(hidden)]
8macro_rules! const_assert_eq {
9 ($left:expr, $right:expr $(,)?) => {
10 const _: [(); $left] = [(); $right];
11 };
12}
13
14#[macro_export]
28macro_rules! assert_nearly_eq {
29 ($left:expr, $right:expr, $(epsilon = $epsilon:expr),* $(, abs_th = $abs_th:expr)?) => {{
31 #[allow(unused_mut)]
32 let mut epsilon = 128.0 * f32::EPSILON;
33 #[allow(unused_mut)]
34 let mut abs_th = f32::MIN;
35
36 $(
37 if stringify!($epsilon) == "epsilon" {
38 epsilon = $epsilon;
39 }
40 )*
41 $(
42 #[allow(clippy::multi_assignments)]
43 if stringify!($abs_th) == "abs_th" {
44 abs_th = $abs_th;
45 }
46 )*
47
48 if !$crate::re::NiMath::nearly_equal($left, $right, $crate::re::NiMath::ComparisonOptions::new(epsilon, abs_th)) {
49 panic!(
50 "Assertion failed: (left: {}, right: {}) are not nearly equal with epsilon: {}, abs_th: {}",
51 $left, $right, epsilon, abs_th
52 );
53 }
54 }};
55 ($left:expr, $right:expr) => {
56 $crate::assert_nearly_eq!($left, $right, epsilon = 128.0 * f32::EPSILON, abs_th = f32::MIN);
57 };
58}