Skip to content
Merged
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
30 changes: 5 additions & 25 deletions include/boost/decimal/cmath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ BOOST_DECIMAL_EXPORT constexpr auto samequantum(decimal64_t lhs, decimal64_t rhs
return samequantumd64(lhs, rhs);
}

BOOST_DECIMAL_EXPORT constexpr auto samequantum(decimal_fast64_t lhs, decimal_fast64_t rhs) noexcept -> bool
{
return samequantumd64f(lhs, rhs);
}

BOOST_DECIMAL_EXPORT constexpr auto samequantum(decimal128_t lhs, decimal128_t rhs) noexcept -> bool
{
return samequantumd128(lhs, rhs);
Expand Down Expand Up @@ -241,31 +246,6 @@ BOOST_DECIMAL_EXPORT constexpr auto quantexp(decimal_fast128_t x) noexcept -> in
return quantexpd128f(x);
}

BOOST_DECIMAL_EXPORT constexpr auto quantize(decimal32_t lhs, decimal32_t rhs) noexcept -> decimal32_t
{
return quantized32(lhs, rhs);
}

BOOST_DECIMAL_EXPORT constexpr auto quantize(decimal_fast32_t lhs, decimal_fast32_t rhs) noexcept -> decimal_fast32_t
{
return quantized32f(lhs, rhs);
}

BOOST_DECIMAL_EXPORT constexpr auto quantize(decimal64_t lhs, decimal64_t rhs) noexcept -> decimal64_t
{
return quantized64(lhs, rhs);
}

BOOST_DECIMAL_EXPORT constexpr auto quantize(decimal128_t lhs, decimal128_t rhs) noexcept -> decimal128_t
{
return quantized128(lhs, rhs);
}

BOOST_DECIMAL_EXPORT constexpr auto quantize(decimal_fast128_t lhs, decimal_fast128_t rhs) noexcept -> decimal_fast128_t
{
return quantized128f(lhs, rhs);
}

} // namespace decimal
} // namespace boost

Expand Down
42 changes: 3 additions & 39 deletions include/boost/decimal/decimal128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <boost/decimal/detail/to_decimal.hpp>
#include <boost/decimal/detail/promotion.hpp>
#include <boost/decimal/detail/check_non_finite.hpp>
#include <boost/decimal/detail/quantize_impl.hpp>
#include <boost/decimal/detail/shrink_significand.hpp>
#include <boost/decimal/detail/cmath/isfinite.hpp>
#include <boost/decimal/detail/cmath/fpclassify.hpp>
Expand Down Expand Up @@ -556,7 +557,8 @@ BOOST_DECIMAL_EXPORT class decimal128_t final
friend BOOST_DECIMAL_CUDA_CONSTEXPR auto quantexpd128(decimal128_t x) noexcept -> int;

// 3.6.6 Quantize
friend BOOST_DECIMAL_CUDA_CONSTEXPR auto quantized128(const decimal128_t& lhs, const decimal128_t& rhs) noexcept -> decimal128_t;
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
friend BOOST_DECIMAL_CUDA_CONSTEXPR auto quantize(T lhs, T rhs) noexcept -> T;

// <cmath> functions that need to be friends
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
Expand Down Expand Up @@ -2161,44 +2163,6 @@ BOOST_DECIMAL_CUDA_CONSTEXPR auto quantexpd128(const decimal128_t x) noexcept ->
return static_cast<int>(x.unbiased_exponent());
}

// 3.6.6
// Returns: a number that is equal in value (except for any rounding) and sign to x,
// and which has an exponent set to be equal to the exponent of y.
// If the exponent is being increased, the value is correctly rounded according to the current rounding mode;
// if the result does not have the same value as x, the "inexact" floating-point exception is raised.
// If the exponent is being decreased and the significand of the result has more digits than the type would allow,
// the "invalid" floating-point exception is raised and the result is NaN.
// If one or both operands are NaN the result is NaN.
// Otherwise, if only one operand is infinity, the "invalid" floating-point exception is raised and the result is NaN.
// If both operands are infinity, the result is DEC_INFINITY, with the same sign as x, converted to the type of x.
// The quantize functions do not signal underflow.
BOOST_DECIMAL_CUDA_CONSTEXPR auto quantized128(const decimal128_t& lhs, const decimal128_t& rhs) noexcept -> decimal128_t
{
#ifndef BOOST_DECIMAL_FAST_MATH
// Return the correct type of nan
if (isnan(lhs))
{
return lhs;
}
else if (isnan(rhs))
{
return rhs;
}

// If one is infinity then return a signaling NAN
if (isinf(lhs) != isinf(rhs))
{
return boost::decimal::from_bits(boost::decimal::detail::d128_snan_mask);
}
else if (isinf(lhs) && isinf(rhs))
{
return lhs;
}
#endif

return {lhs.full_significand(), rhs.biased_exponent(), lhs.isneg()};
}

BOOST_DECIMAL_CUDA_CONSTEXPR auto copysignd128(decimal128_t mag, const decimal128_t sgn) noexcept -> decimal128_t
{
mag.edit_sign(sgn.isneg());
Expand Down
42 changes: 3 additions & 39 deletions include/boost/decimal/decimal32_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <boost/decimal/detail/to_decimal.hpp>
#include <boost/decimal/detail/promotion.hpp>
#include <boost/decimal/detail/check_non_finite.hpp>
#include <boost/decimal/detail/quantize_impl.hpp>
#include <boost/decimal/detail/shrink_significand.hpp>
#include <boost/decimal/detail/cmath/isfinite.hpp>
#include <boost/decimal/detail/cmath/fpclassify.hpp>
Expand Down Expand Up @@ -564,7 +565,8 @@ BOOST_DECIMAL_EXPORT class decimal32_t final // NOLINT(cppcoreguidelines-special
friend constexpr auto quantexpd32(decimal32_t x) noexcept -> int;

// 3.6.6 Quantize
friend constexpr auto quantized32(decimal32_t lhs, decimal32_t rhs) noexcept -> decimal32_t;
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
friend BOOST_DECIMAL_CUDA_CONSTEXPR auto quantize(T lhs, T rhs) noexcept -> T;

// <cmath> functions that need to be friends
friend constexpr auto copysignd32(decimal32_t mag, decimal32_t sgn) noexcept -> decimal32_t;
Expand Down Expand Up @@ -2259,44 +2261,6 @@ constexpr auto quantexpd32(const decimal32_t x) noexcept -> int
return static_cast<int>(x.unbiased_exponent());
}

// 3.6.6
// Returns: a number that is equal in value (except for any rounding) and sign to x,
// and which has an exponent set to be equal to the exponent of y.
// If the exponent is being increased, the value is correctly rounded according to the current rounding mode;
// if the result does not have the same value as x, the "inexact" floating-point exception is raised.
// If the exponent is being decreased and the significand of the result has more digits than the type would allow,
// the "invalid" floating-point exception is raised and the result is NaN.
// If one or both operands are NaN the result is NaN.
// Otherwise, if only one operand is infinity, the "invalid" floating-point exception is raised and the result is NaN.
// If both operands are infinity, the result is DEC_INFINITY, with the same sign as x, converted to the type of x.
// The quantize functions do not signal underflow.
constexpr auto quantized32(const decimal32_t lhs, const decimal32_t rhs) noexcept -> decimal32_t
{
#ifndef BOOST_DECIMAL_FAST_MATH
// Return the correct type of nan
if (isnan(lhs))
{
return lhs;
}
if (isnan(rhs))
{
return rhs;
}

// If one is infinity then return a signaling NAN
if (isinf(lhs) != isinf(rhs))
{
return from_bits(detail::d32_snan_mask);
}
if (isinf(lhs) && isinf(rhs))
{
return lhs;
}
#endif

return {lhs.full_significand(), rhs.biased_exponent(), lhs.isneg()};
}

constexpr auto scalblnd32(decimal32_t num, const long exp) noexcept -> decimal32_t
{
#ifndef BOOST_DECIMAL_FAST_MATH
Expand Down
42 changes: 3 additions & 39 deletions include/boost/decimal/decimal64_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <boost/decimal/detail/comparison.hpp>
#include <boost/decimal/detail/mixed_decimal_arithmetic.hpp>
#include <boost/decimal/detail/check_non_finite.hpp>
#include <boost/decimal/detail/quantize_impl.hpp>
#include <boost/decimal/detail/shrink_significand.hpp>
#include <boost/decimal/detail/cmath/isfinite.hpp>
#include <boost/decimal/detail/cmath/fpclassify.hpp>
Expand Down Expand Up @@ -575,7 +576,8 @@ BOOST_DECIMAL_EXPORT class decimal64_t final
friend BOOST_DECIMAL_CUDA_CONSTEXPR auto quantexpd64(decimal64_t x) noexcept -> int;

// 3.6.6 Quantize
friend BOOST_DECIMAL_CUDA_CONSTEXPR auto quantized64(decimal64_t lhs, decimal64_t rhs) noexcept -> decimal64_t;
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
friend BOOST_DECIMAL_CUDA_CONSTEXPR auto quantize(T lhs, T rhs) noexcept -> T;

// <cmath> functions that need to be friends
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
Expand Down Expand Up @@ -2167,44 +2169,6 @@ BOOST_DECIMAL_CUDA_CONSTEXPR auto quantexpd64(const decimal64_t x) noexcept -> i
return static_cast<int>(x.unbiased_exponent());
}

// 3.6.6
// Returns: a number that is equal in value (except for any rounding) and sign to x,
// and which has an exponent set to be equal to the exponent of y.
// If the exponent is being increased, the value is correctly rounded according to the current rounding mode;
// if the result does not have the same value as x, the "inexact" floating-point exception is raised.
// If the exponent is being decreased and the significand of the result has more digits than the type would allow,
// the "invalid" floating-point exception is raised and the result is NaN.
// If one or both operands are NaN the result is NaN.
// Otherwise, if only one operand is infinity, the "invalid" floating-point exception is raised and the result is NaN.
// If both operands are infinity, the result is DEC_INFINITY, with the same sign as x, converted to the type of x.
// The quantize functions do not signal underflow.
BOOST_DECIMAL_CUDA_CONSTEXPR auto quantized64(const decimal64_t lhs, const decimal64_t rhs) noexcept -> decimal64_t
{
#ifndef BOOST_DECIMAL_FAST_MATH
// Return the correct type of nan
if (isnan(lhs))
{
return lhs;
}
if (isnan(rhs))
{
return rhs;
}

// If one is infinity then return a signaling NAN
if (isinf(lhs) != isinf(rhs))
{
return boost::decimal::from_bits(boost::decimal::detail::d64_snan_mask);
}
if (isinf(lhs) && isinf(rhs))
{
return lhs;
}
#endif

return {lhs.full_significand(), rhs.biased_exponent(), lhs.isneg()};
}

BOOST_DECIMAL_CUDA_CONSTEXPR auto scalblnd64(decimal64_t num, const long exp) noexcept -> decimal64_t
{
#ifndef BOOST_DECIMAL_FAST_MATH
Expand Down
42 changes: 3 additions & 39 deletions include/boost/decimal/decimal_fast128_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <boost/decimal/detail/to_decimal.hpp>
#include <boost/decimal/detail/promotion.hpp>
#include <boost/decimal/detail/check_non_finite.hpp>
#include <boost/decimal/detail/quantize_impl.hpp>
#include <boost/decimal/detail/shrink_significand.hpp>
#include <boost/decimal/detail/cmath/isfinite.hpp>
#include <boost/decimal/detail/cmath/fpclassify.hpp>
Expand Down Expand Up @@ -499,7 +500,8 @@ BOOST_DECIMAL_EXPORT class alignas(16) decimal_fast128_t final
friend constexpr auto quantexpd128f(const decimal_fast128_t& x) noexcept -> int;

// 3.6.6 Quantize
friend constexpr auto quantized128f(const decimal_fast128_t& lhs, const decimal_fast128_t& rhs) noexcept -> decimal_fast128_t;
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
friend BOOST_DECIMAL_CUDA_CONSTEXPR auto quantize(T lhs, T rhs) noexcept -> T;
};

#ifdef _MSC_VER
Expand Down Expand Up @@ -1696,44 +1698,6 @@ constexpr auto quantexpd128f(const decimal_fast128_t& x) noexcept -> int
return static_cast<int>(x.unbiased_exponent());
}

// 3.6.6
// Returns: a number that is equal in value (except for any rounding) and sign to x,
// and which has an exponent set to be equal to the exponent of y.
// If the exponent is being increased, the value is correctly rounded according to the current rounding mode;
// if the result does not have the same value as x, the "inexact" floating-point exception is raised.
// If the exponent is being decreased and the significand of the result has more digits than the type would allow,
// the "invalid" floating-point exception is raised and the result is NaN.
// If one or both operands are NaN the result is NaN.
// Otherwise, if only one operand is infinity, the "invalid" floating-point exception is raised and the result is NaN.
// If both operands are infinity, the result is DEC_INFINITY, with the same sign as x, converted to the type of x.
// The quantize functions do not signal underflow.
constexpr auto quantized128f(const decimal_fast128_t& lhs, const decimal_fast128_t& rhs) noexcept -> decimal_fast128_t
{
#ifndef BOOST_DECIMAL_FAST_MATH
// Return the correct type of nan
if (isnan(lhs))
{
return lhs;
}
else if (isnan(rhs))
{
return rhs;
}

// If one is infinity then return a signaling NAN
if (isinf(lhs) != isinf(rhs))
{
return boost::decimal::direct_init_d128(boost::decimal::detail::d128_fast_qnan, 0, false);
}
else if (isinf(lhs) && isinf(rhs))
{
return lhs;
}
#endif

return {lhs.full_significand(), rhs.biased_exponent(), lhs.isneg()};
}

#if !defined(BOOST_DECIMAL_DISABLE_CLIB)

constexpr decimal_fast128_t::decimal_fast128_t(const char* str, const std::size_t len)
Expand Down
41 changes: 3 additions & 38 deletions include/boost/decimal/decimal_fast32_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <boost/decimal/detail/to_decimal.hpp>
#include <boost/decimal/detail/promotion.hpp>
#include <boost/decimal/detail/check_non_finite.hpp>
#include <boost/decimal/detail/quantize_impl.hpp>
#include <boost/decimal/detail/shrink_significand.hpp>
#include <boost/decimal/detail/cmath/isfinite.hpp>
#include <boost/decimal/detail/cmath/fpclassify.hpp>
Expand Down Expand Up @@ -497,7 +498,8 @@ BOOST_DECIMAL_EXPORT class alignas(4) decimal_fast32_t final
// Specific decimal functionality
friend constexpr auto samequantumd32f(decimal_fast32_t lhs, decimal_fast32_t rhs) noexcept -> bool;
friend constexpr auto quantexpd32f(decimal_fast32_t x) noexcept -> int;
friend constexpr auto quantized32f(decimal_fast32_t lhs, decimal_fast32_t rhs) noexcept -> decimal_fast32_t;
template <BOOST_DECIMAL_DECIMAL_FLOATING_TYPE T>
friend BOOST_DECIMAL_CUDA_CONSTEXPR auto quantize(T lhs, T rhs) noexcept -> T;
};

#ifdef _MSC_VER
Expand Down Expand Up @@ -1684,43 +1686,6 @@ constexpr auto quantexpd32f(const decimal_fast32_t x) noexcept -> int
return static_cast<int>(x.unbiased_exponent());
}

// Returns: a number that is equal in value (except for any rounding) and sign to x,
// and which has an exponent set to be equal to the exponent of y.
// If the exponent is being increased, the value is correctly rounded according to the current rounding mode;
// if the result does not have the same value, as x, the "inexact" floating-point exception is raised.
// If the exponent is being decreased and the significand of the result has more digits than the type would allow,
// the "invalid" floating-point exception is raised and the result is NaN.
// If one or both operands are NaN, the result is NaN.
// Otherwise, if only one operand is infinity, the "invalid" floating-point exception is raised and the result is NaN.
// If both operands are infinity, the result is DEC_INFINITY, with the same sign as x, converted to the type of x.
// The quantize functions do not signal underflow.
constexpr auto quantized32f(const decimal_fast32_t lhs, const decimal_fast32_t rhs) noexcept -> decimal_fast32_t
{
#ifndef BOOST_DECIMAL_FAST_MATH
// Return the correct type of nan
if (isnan(lhs))
{
return lhs;
}
else if (isnan(rhs))
{
return rhs;
}

// If one is infinity then return a signaling NAN
if (isinf(lhs) != isinf(rhs))
{
return direct_init(detail::d32_fast_snan, UINT8_C(0));
}
else if (isinf(lhs) && isinf(rhs))
{
return lhs;
}
#endif

return {lhs.full_significand(), rhs.biased_exponent(), lhs.isneg()};
}

#if !defined(BOOST_DECIMAL_DISABLE_CLIB)

constexpr decimal_fast32_t::decimal_fast32_t(const char* str, const std::size_t len)
Expand Down
Loading
Loading