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
5 changes: 3 additions & 2 deletions include/xsimd/arch/common/xsimd_common_trigo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ namespace xsimd

return select(y == real_batch(0.),
select(fabs(x) > real_batch(1.),
batch_type(constants::pio2<real_batch>(), real_batch(0.)),
batch_type(asin(x), real_batch(0.))),
batch_type(copysign(constants::pio2<real_batch>(), x),
copysign(acosh(max(fabs(x), real_batch(1.))), y)),
batch_type(asin(x), y)),
resg);
}

Expand Down
44 changes: 44 additions & 0 deletions test/test_complex_trigonometric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ struct complex_trigonometric_test
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}
check_real_axis([](const batch_type& z)
{ return asin(z); },
[](const value_type& v)
{ return std::asin(v); });
}

void test_acos()
Expand All @@ -139,6 +143,10 @@ struct complex_trigonometric_test
detail::load_batch(ref, expected, i);
CHECK_BATCH_EQ(ref, out);
}
check_real_axis([](const batch_type& z)
{ return acos(z); },
[](const value_type& v)
{ return std::acos(v); });
}

void test_atan()
Expand All @@ -157,6 +165,42 @@ struct complex_trigonometric_test
}

private:
template <class BatchFn, class ScalarFn>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do this:

template <class BatchFn, class ScalarFn>
void check_real_axis(BatchFn batch_fn, ScalarFn scalar_fn)
{
    using R = real_value_type;
    const R outside = std::nextafter(R(1), R(2));
    const std::array<R, 8> re = { -R(4), -outside, -R(1), -R(0), R(0), R(1), outside, R(4) };
    const std::array<R, 8> im = { -R(2), -R(1), -R(0.5), -R(0), R(0), R(0.5), R(1), R(2) };
    const std::size_t n = re.size() * im.size();

    // Round up to a multiple of `size`. The tail stays value_type(0, 0),
    // which is already in the grid.
    vector_type inputs((n + size - 1) / size * size);
    auto it = inputs.begin();
    for (R real : re)
    {
        for (R imag : im)
        {
            *it++ = value_type(real, imag);
        }
    }

    vector_type expected(inputs.size());
    std::transform(inputs.cbegin(), inputs.cend(), expected.begin(), scalar_fn);

    for (std::size_t i = 0; i < inputs.size(); i += size)
    {
        batch_type in, ref;
        detail::load_batch(in, inputs, i);
        detail::load_batch(ref, expected, i);
        CHECK_BATCH_EQ(ref, batch_fn(in));
    }
}

void check_real_axis(BatchFn batch_fn, ScalarFn scalar_fn)
{
using R = real_value_type;
const R zero(0);
const R outside = std::nextafter(R(1), R(2));
const R re[] = { -R(4), -outside, -R(1), -zero, zero, R(1), outside, R(4) };
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 = batch_fn(in);
vector_type scalar(size);
for (size_t lane = 0; lane < size; ++lane)
{
scalar[lane] = scalar_fn(inputs[i + lane]);
}
detail::load_batch(ref, scalar, 0);
CHECK_BATCH_EQ(ref, out);
}
}

void test_tan_impl()
{
std::transform(input.cbegin(), input.cend(), expected.begin(),
Expand Down