Use a threshold for utils::inv and simd_inv
This commit is contained in:
@@ -19,16 +19,19 @@ pub trait WReal: SimdRealField<Element = Real> + Copy {}
|
|||||||
impl WReal for Real {}
|
impl WReal for Real {}
|
||||||
impl WReal for SimdReal {}
|
impl WReal for SimdReal {}
|
||||||
|
|
||||||
|
const INV_EPSILON: Real = 1.0e-20;
|
||||||
|
|
||||||
pub(crate) fn inv(val: Real) -> Real {
|
pub(crate) fn inv(val: Real) -> Real {
|
||||||
if val == 0.0 {
|
if val >= -INV_EPSILON && val <= INV_EPSILON {
|
||||||
0.0
|
0.0
|
||||||
} else {
|
} else {
|
||||||
1.0 / val
|
1.0 / val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn simd_inv<N: SimdRealField + Copy>(val: N) -> N {
|
pub(crate) fn simd_inv<N: WReal>(val: N) -> N {
|
||||||
N::zero().select(val.simd_eq(N::zero()), N::one() / val)
|
let eps = N::splat(INV_EPSILON);
|
||||||
|
N::zero().select(val.simd_gt(-eps) & val.simd_lt(eps), N::one() / val)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait to copy the sign of each component of one scalar/vector/matrix to another.
|
/// Trait to copy the sign of each component of one scalar/vector/matrix to another.
|
||||||
|
|||||||
Reference in New Issue
Block a user