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
4 changes: 3 additions & 1 deletion include/xsimd/arch/common/xsimd_common_math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,9 @@ namespace xsimd
{
using batch_type = batch<std::complex<T>, A>;
using real_batch = typename batch_type::real_batch;
batch_type u = 1 + self;
Comment thread
agourakis82 marked this conversation as resolved.
Resolved
// Scalar and complex broadcasts add a positive zero to the imaginary part.
// Translate the real part directly to preserve an imaginary negative zero.
batch_type u(real_batch(1.) + self.real(), self.imag());
batch_type logu = log(u);
return select(u == batch_type(1.),
self,
Expand Down
33 changes: 33 additions & 0 deletions test/test_complex_exponential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,39 @@ struct complex_exponential_test
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}

using R = real_value_type;
const R zero(0);
const R below = std::nextafter(R(-1), R(-2));
const R re[] = { -R(4), -R(2), below, -R(0.5), -zero, zero, R(0.5), R(2) };
const R im[] = { -R(1), -R(0.5), -R(0.25), -zero, zero, R(0.25), R(0.5), R(1) };
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 = log1p(in);
vector_type scalar(size);
for (size_t lane = 0; lane < size; ++lane)
{
const value_type& z = inputs[i + lane];
scalar[lane] = std::log(value_type(R(1) + z.real(), z.imag()));
}
detail::load_batch(ref, scalar, 0);
CHECK_BATCH_EQ(ref, out);
}
}

void test_sign()
Expand Down