diff options
author | Antonio Sanchez <cantonios@google.com> | 2021-02-12 11:32:29 -0800 |
---|---|---|
committer | Rasmus Munk Larsen <rmlarsen@google.com> | 2021-02-17 02:23:24 +0000 |
commit | 7ff0b7a980ceffe7d0e72ebac924f514f7874e9b (patch) | |
tree | 4022a25c9e1c909aff3f43b978a4a5d5ce0a1c47 /test/packetmath.cpp | |
parent | 9ad4096ccb75dd5c5dd882576d49d48475afa300 (diff) |
Updated pfrexp implementation.
The original implementation fails for 0, denormals, inf, and NaN.
See #2150
Diffstat (limited to 'test/packetmath.cpp')
-rw-r--r-- | test/packetmath.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/packetmath.cpp b/test/packetmath.cpp index c388f3a31..94a83c008 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -567,7 +567,36 @@ void packetmath_real() { data2[i] = Scalar(internal::random<double>(-87, 88)); } CHECK_CWISE1_IF(PacketTraits::HasExp, std::exp, internal::pexp); + CHECK_CWISE1_BYREF1_IF(PacketTraits::HasExp, REF_FREXP, internal::pfrexp); + if (PacketTraits::HasExp) { + // Check denormals: + for (int j=0; j<3; ++j) { + data1[0] = Scalar(std::ldexp(1, std::numeric_limits<Scalar>::min_exponent-j)); + CHECK_CWISE1_BYREF1_IF(PacketTraits::HasExp, REF_FREXP, internal::pfrexp); + data1[0] = -data1[0]; + CHECK_CWISE1_BYREF1_IF(PacketTraits::HasExp, REF_FREXP, internal::pfrexp); + } + + // zero + data1[0] = Scalar(0); + CHECK_CWISE1_BYREF1_IF(PacketTraits::HasExp, REF_FREXP, internal::pfrexp); + + // inf and NaN only compare output fraction, not exponent. + test::packet_helper<PacketTraits::HasExp,Packet> h; + Packet pout; + Scalar sout; + Scalar special[] = { NumTraits<Scalar>::infinity(), + -NumTraits<Scalar>::infinity(), + NumTraits<Scalar>::quiet_NaN()}; + for (int i=0; i<3; ++i) { + data1[0] = special[i]; + ref[0] = Scalar(REF_FREXP(data1[0], ref[PacketSize])); + h.store(data2, internal::pfrexp(h.load(data1), h.forward_reference(pout, sout))); + VERIFY(test::areApprox(ref, data2, 1) && "internal::pfrexp"); + } + } + for (int i = 0; i < PacketSize; ++i) { data1[i] = Scalar(internal::random<double>(-1, 1)); data2[i] = Scalar(internal::random<double>(-1, 1)); |