Skip to content

Commit d303f97

Browse files
committed
Fixed bitsign under ffast-math
1 parent e7edad8 commit d303f97

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/xsimd/arch/generic/xsimd_generic_math.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,22 @@ namespace xsimd
9595
template <class A>
9696
inline batch<float, A> bitofsign(batch<float, A> const& self, requires_arch<generic>) noexcept
9797
{
98+
// Under fast-math, the compiler might replace minus zero by zero
99+
#ifdef __FAST_MATH__
100+
return self & bitwise_cast<float>(batch<uint32_t, A>::broadcast(0x80000000u));
101+
#else
98102
return self & constants::minuszero<batch<float, A>>();
103+
#endif
99104
}
100105
template <class A>
101106
inline batch<double, A> bitofsign(batch<double, A> const& self, requires_arch<generic>) noexcept
102107
{
108+
// Under fast-math, the compiler might replace minus zero by zero
109+
#ifdef __FAST_MATH__
110+
return self & bitwise_cast<double>(batch<uint64_t, A>::broadcast(0x8000000000000000lu));
111+
#else
103112
return self & constants::minuszero<batch<double, A>>();
113+
#endif
104114
}
105115

106116
// bitwise_cast

0 commit comments

Comments
 (0)