Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion include/xsimd/arch/common/xsimd_common_trigo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,11 @@ namespace xsimd
auto y = z.imag();
real_batch two(2);
auto d = cosh(two * x) + cos(two * y);
return { sinh(two * x) / d, sin(two * y) / d };
auto real_part = sinh(two * x) / d;
#ifndef __FAST_MATH__
real_part = select(isinf(d), copysign(real_batch(1), x), real_part);
#endif
return { real_part, sin(two * y) / d };
}

}
Expand Down
35 changes: 35 additions & 0 deletions test/test_complex_hyperbolic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ struct complex_hyperbolic_test
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}

#ifndef __FAST_MATH__
// Fast-math drops overflow recovery and does not match std::tanh.
using R = real_value_type;
const R zero(0);
const R huge = std::is_same_v<R, float> ? R(45) : R(356);
const R re[] = { -huge, -R(20), -R(1), -zero, zero, R(1), R(20), huge };
const R im[] = { -R(2), -R(1), -R(0.5), -zero, zero, R(0.5), R(1), R(2) };
vector_type inputs;
inputs.reserve(64 + size);
for (R real : re)
{
for (R imag : im)
{
inputs.push_back(value_type(real, imag));
}
}
while (inputs.size() % size != 0)
{
inputs.push_back(inputs.front());
}
for (size_t i = 0; i < inputs.size(); i += size)
{
batch_type in, out, ref;
detail::load_batch(in, inputs, i);
out = tanh(in);
vector_type scalar(size);
for (size_t lane = 0; lane < size; ++lane)
{
scalar[lane] = std::tanh(inputs[i + lane]);
}
detail::load_batch(ref, scalar, 0);
CHECK_BATCH_EQ(ref, out);
}
#endif
}

void test_asinh()
Expand Down