@@ -29,21 +29,15 @@ inline QuarticallyInterpolatedMapping::QuarticallyInterpolatedMapping(const doub
2929 LogLikeIndexMapping<QuarticallyInterpolatedMapping>(gamma, index_offset) {}
3030
3131inline double QuarticallyInterpolatedMapping::log (const double &value) const {
32- int64_t value_bits ;
33- std::memcpy (&value_bits, & value, sizeof (value_bits)) ;
32+ int exponent = 0 ;
33+ const double mantissa = 2 * std::frexp ( value, &exponent) - 1 ;
3434
35- const int64_t mantissa_plus_one_bits = (value_bits & 0x000FFFFFFFFFFFFFL ) | 0x3FF0000000000000L ;
36- double mantissa_plus_one;
37- std::memcpy (&mantissa_plus_one, &mantissa_plus_one_bits, sizeof (mantissa_plus_one_bits));
38- double mantissa = mantissa_plus_one - 1.0 ;
39-
40- const double exponent = static_cast <double >(((value_bits & 0x7FF0000000000000L ) >> 52 ) - 1023 );
41- return (((A * mantissa + B) * mantissa + C) * mantissa + D) * mantissa + exponent;
35+ return (((A * mantissa + B) * mantissa + C) * mantissa + D) * mantissa + exponent - 1 ;
4236}
4337
4438inline double QuarticallyInterpolatedMapping::log_inverse (const double &index) const {
45- const int64_t exponent = static_cast <int64_t >(std::floor (index));
46- const double e = exponent - index;
39+ const auto exponent = static_cast <int >(std::floor (index));
40+ const double e = static_cast < double >( exponent) - index;
4741
4842 // Derived from Ferrari's method
4943 const double alpha = -(3 * B * B) / (8 * A * A) + C / A; // 2.5
@@ -57,16 +51,10 @@ inline double QuarticallyInterpolatedMapping::log_inverse(const double &index) c
5751 const double w = std::sqrt (alpha + 2 * y);
5852 const double x = (-B / (4 * A) + (w - std::sqrt (-(3 * alpha + 2 * y + (2 * beta) / w))) / 2 ) + 1 ;
5953
60- int64_t result_bits = (static_cast <uint64_t >(exponent + 1023 ) << 52 ) & 0x7FF0000000000000L ;
61-
62- uint64_t x_plus_one_bits;
63- std::memcpy (&x_plus_one_bits, &x, sizeof (x));
64-
65- result_bits |= (x_plus_one_bits & 0x000FFFFFFFFFFFFFL );
66-
67- double result;
68- std::memcpy (&result, &result_bits, sizeof (result_bits));
69- return result;
54+ int tmp = 0 ;
55+ double m = std::frexp (x, &tmp);
56+ double sig = 2.0 * m;
57+ return std::ldexp (sig, exponent);
7058}
7159
7260inline IndexMappingLayout QuarticallyInterpolatedMapping::layout () const {
0 commit comments