<cmath> Support :: Boost.Decimal

# `<cmath>` Support

Decimal contains overloads for all functions from `<cmath>`, and they have the same handling as built-in floating point types. They are also all constexpr with C++14 unlike the built-in floating point types which require either C++23 or 26. Additionally, all functions are marked `noexcept`.

All of these functions are impacted by the global rounding mode as described in rounding modes as well as the `DEC_FLT_EVAL_METHOD` from evaluation methods.

## Basic Operations

Function | Description
abs | Absolute Value
fabs | Floating Point Absolute Value (Identical to `abs`)
fmod | Floating Point Modulo Operation
remainder | Signed Floating Point Modulo
remquo | Signed remainder and at least three bits of division result (quotient)
fma | Fused Multiply - Add
fmax | Returns maximum value
fmin | Returns minimum value
fdim | Returns unsigned difference of two values
nan | Generates Quiet NANs with Payload
snan | Generates Signaling NANs with Payload (Non-Standard)

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr DecimalType abs(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType fabs(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType abs(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType fmod(DecimalType x, DecimalType y) noexcept;

    template <typename DecimalType>
    constexpr DecimalType remainder(DecimalType x, DecimalType y) noexcept;

    template <typename DecimalType>
    constexpr DecimalType remquo(DecimalType x, DecimalType y, int* quo) noexcept;

    template <typename DecimalType>
    constexpr DecimalType fma(DecimalType x, DecimalType y, DecimalType z) noexcept;

    template <typename DecimalType>
    constexpr DecimalType fmax(DecimalType x, DecimalType y, int* quo) noexcept;

    template <typename DecimalType>
    constexpr DecimalType fmin(DecimalType x, DecimalType y, int* quo) noexcept;

    template <typename DecimalType>
    constexpr DecimalType fdim(DecimalType x, DecimalType y, int* quo) noexcept;

    constexpr decimal32_t nand32(const char* arg) noexcept;
    constexpr decimal64_t nand64(const char* arg) noexcept;
    constexpr decimal128_t nand128(const char* arg) noexcept;

    constexpr decimal_fast32_t nand32f(const char* arg) noexcept;
    constexpr decimal_fast64_t nand64f(const char* arg) noexcept;
    constexpr decimal_fast128_t nand128f(const char* arg) noexcept;

    constexpr decimal32_t snand32(const char* arg) noexcept;
    constexpr decimal64_t snand64(const char* arg) noexcept;
    constexpr decimal128_t snand128(const char* arg) noexcept;

    constexpr decimal_fast32_t snand32f(const char* arg) noexcept;
    constexpr decimal_fast64_t snand64f(const char* arg) noexcept;
    constexpr decimal_fast128_t snand128f(const char* arg) noexcept;

    } // namespace decimal
    } // namespace boost

## Exponential Functions

Function | Description
exp | Returns `e` to the given power
exp2 | Returns `2` to the given power
expm1 | Returns (`e^x` - 1)
log | Returns the natural logarithm of the value (base `e`)
log10 | Returns the log base 10 of the value
log2 | Returns the log base 2 of the value
log1p | Returns ln(1 + x)

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr DecimalType exp(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType exp2(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType expm1(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType log(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType log10(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType log2(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType log1p(DecimalType x) noexcept;

    } // namespace decimal
    } // namespace boost

## Power Functions

Function | Description
pow | Returns x^y
sqrt | Returns the square root of the value
cbrt | Returns the cube root of the value
hypot | Returns sqrt(x^2 + y^2) or sqrt(x^2 + y^2 + z^2) depending on number of arguments

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr DecimalType pow(DecimalType x, DecimalType y) noexcept;

    template <typename DecimalType>
    constexpr DecimalType sqrt(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType cbrt(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType hypot(DecimalType x, DecimalType y) noexcept;

    template <typename DecimalType>
    constexpr DecimalType hypot(DecimalType x, DecimalType y, DecimalType z) noexcept;

    } // namespace decimal
    } // namespace boost

## Trigonometric Functions

Function | Description
sin | Computes sin(x)
cos | Computes cos(x)
tan | Computes tan(x)
asin | Computes arcsin(x)
acos | Computes arccos(x)
atan | Computes arctan(x)
atan2 | Computes arctan(x) using signs as quadrants

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr DecimalType sin(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType cos(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType tan(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType asin(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType acos(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType atan(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType atan2(DecimalType x, DecimalType y) noexcept;

    } // namespace decimal
    } // namespace boost

## Hyperbolic Functions

Function | Description
sinh | Computes hyperbolic sin sinh(x)
cosh | Computes hyperbolic cos cosh(x)
tanh | Computes hyperbolic tan tanh(x)
asinh | Computes hyperbolic arcsin asinh(x)
acosh | Computes hyperbolic arccos acosh(x)
atanh | Computes hyperbolic arctan atanh(x)

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr DecimalType sinh(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType cosh(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType tanh(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType asinh(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType acosh(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType atanh(DecimalType x) noexcept;

    } // namespace decimal
    } // namespace boost

## Error and Gamma Functions

Function | Description
erf | Computes the error function erf(x)
erfc | Computes the complementary error function erfc(x)
tgamma | Computes the gamma function gamma(x)
lgamma | Computes the natural log of the gamma function ln(gamma(x))

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr DecimalType erf(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType erfc(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType tgamma(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType lgamma(DecimalType x) noexcept;

    } // namespace decimal
    } // namespace boost

## Nearest integer floating point operations

Function | Description
ceil | Computes the nearest integer not less than the given value
floor | Computes the nearest integer not greater than the given value
trunc | Computes the nearest integer not greater in magnitude than the given value
round | Computes the nearest integer represented in same decimal format rounding away from zero
lround | Computes the nearest `long` rounding away from zero
llround | Computes the nearest `long long` rounding away from zero
nearbyint | Computest the nearest integer represented in same decimal format subject to current fenv rounding mode
lrint | Computest the nearest `long` subject to current fenv rounding mode
llrint | Computest the nearest `long long` subject to current fenv rounding mode

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr DecimalType ceil(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType floor(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType trunc(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType round(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr long lround(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr long long llround(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType nearbyint(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType rint(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr long lrint(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr long long llrint(DecimalType x) noexcept;

    } // namespace decimal
    } // namespace boost

## Floating Point Manipulation Functions

Function | Description
frexp | Returns significand and base 2 exponent
ldexp | Multiplies a number by 2^x
modf | Decomposes a number into integer and fractional parts
scalbn | Multiplies a decimal number by `FLT_RADIX` (10) raised to an `int` power
scalbln | Multiplies a decimal number by `FLT_RADIX` (10) raised to an `long` power
ilogb | Extracts `int` exponent of a number
logb | Extracts Decimal Type exponent of a number
nextafter | Next representable decimal type value
nexttowards | Next representable decimal type value towards a `long double`
copysign | Copies the sign of a decimal value

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr DecimalType frexp(DecimalType x, int* exp) noexcept;

    template <typename DecimalType>
    constexpr DecimalType ldexp(DecimalType x, int exp) noexcept;

    template <typename DecimalType>
    constexpr DecimalType modf(DecimalType x, DecimalType* iptr) noexcept;

    template <typename DecimalType>
    constexpr DecimalType scalbn(DecimalType x, int exp) noexcept;

    template <typename DecimalType>
    constexpr DecimalType scalbln(DecimalType x, long exp) noexcept;

    template <typename DecimalType>
    constexpr int ilogb(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType logb(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType nextafter(DecimalType from, DecimalType to) noexcept;

    template <typename DecimalType>
    constexpr DecimalType nexttoward(DecimalType from, long double to) noexcept;

    template <typename DecimalType>
    constexpr DecimalType copysign(DecimalType mag, DecimalType sgn) noexcept;

    } // namespace decimal
    } // namespace boost

## Classification and Comparison

Function | Description
fpclassify | Categorizes a value
isfinite | Checks if a given value is finite
isinf | Checks if a given value is infinite
isnan | Checks if a given value is a NAN
isnormal | Checks if a given value is normal
signbit | Checks the sign of a value
isgreater | Checks if the LHS (Left-hand side or first parameter) is greater than the RHS (Right-hand side or second parameter)
isgreaterequal | Checks if the LHS is greater than or equal to the RHS
isless | Checks if the LHS is less than the RHS
islessequal | Checks if the LHS is less than or equal to the RHS
isunordered | Checks if the LHS and RHS are unordered (i.e. if one or both are NAN)

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr int fpclassify(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr bool isfinite(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr bool isinf(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr bool isnan(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr bool isnormal(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr bool signbit(DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr bool isgreater(DecimalType x, DecimalType y) noexcept;

    template <typename DecimalType>
    constexpr bool isgreaterequal(DecimalType x, DecimalType y) noexcept;

    template <typename DecimalType>
    constexpr bool isless(DecimalType x, DecimalType y) noexcept;

    template <typename DecimalType>
    constexpr bool islessgreater(DecimalType x, DecimalType y) noexcept;

    template <typename DecimalType>
    constexpr bool isunordered(DecimalType x, DecimalType y) noexcept;

    } // namespace decimal
    } // namespace boost

## Special Functions

These are the special functions that were added in C++17.

| This section does not currently contain all functions specified by C++17, but it does contain the ones that are more commonly useful like the Beta Function.

The following functions have been implemented for decimal types:

Function | Description
assoc_laguerre | Associated Laguerre Polynomials
assoc_legendre | Associated Legendre Polynomials
beta | Calculates the beta function
comp_ellint_1 | Calculates the complete elliptic integrals of the first kind
comp_ellint_2 | Calculates the complete elliptic integrals of the second kind
ellint_1 | Calculates the incomplete elliptic integrals of the first kind
ellint_2 | Calculates the incomplete elliptic integrals of the second kind
hermite | Hermite Polynomials
laguerre | Laguerre Polynomials
legendre | Legendre Polynomials
riemann_zeta | Computes the Riemann Zeta function

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr DecimalType assoc_laguerre(unsigned int n, unsigned int m, DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType assoc_legendre(unsigned int n, unsigned int m, DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType beta(DecimalType x, DecimalType y) noexcept;

    template <typename DecimalType>
    constexpr auto comp_ellint_1(DecimalType k) noexcept;

    template <typename DecimalType>
    constexpr auto comp_ellint_2(DecimalType k) noexcept;

    template <typename DecimalType>
    constexpr auto ellint_1(DecimalType k, DecimalType phi) noexcept;

    template <typename DecimalType>
    constexpr auto ellint_2(DecimalType k, DecimalType phi) noexcept;

    template <typename DecimalType>
    constexpr DecimalType hermite(unsigned int n, DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType laguerre(unsigned int n, DecimalType x) noexcept;

    template <typename DecimalType>
    constexpr DecimalType legendre(unsigned int n, DecimalType x) noexcept;

    template <typename DecimalType, typename IntegralType>
    constexpr DecimalType riemann_zeta(IntegralType n) noexcept;

    } //namespace decimal
    } //namespace boost

## Non-standard Functions

The following are convenience functions, or are prescribed in IEEE 754-2019 as required for decimal floating point types.

### `issignaling`

    template <typename Decimal>
    constexpr bool issignaling(Decimal x) noexcept;

Effects: If x is an sNaN returns true, otherwise returns false. This function does not signal even if x is an sNaN per IEEE 754 section 5.7.2.

### `read_payload`

    template <typename Decimal>
    constexpr auto read_payload(Decimal x) noexcept
        -> typename T::significand_type;

Effects: if x is either a qNaN or an sNaN, returns the payload of the NaN, otherwise returns 0.

This function allows the payloads of nans that are set by the functions `nan` or `snan` to be returned.

### `samequantum`

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename Decimal>
    constexpr bool samequantum(Decimal x, Decimal y) noexcept;

    constexpr bool samequantumd32(decimal32_t x, decimal32_t y) noexcept;
    constexpr bool samequantumd64(decimal64_t x, decimal64_t y) noexcept;
    constexpr bool samequantumd128(decimal128_t x, decimal128_t y) noexcept;

    } // namespace decimal
    } // namepsace boost

Effects: Determines if the quantum (unbiased) exponents of x and y are the same.

If both x and y are NaN, or infinity, they have the same quantum exponents.

If exactly one operand is infinity or exactly one operand is NaN, they do not have the same quantum exponents.

### `quantexp`

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename Decimal>
    constexpr int quantexp(Decimal x) noexcept;

    constexpr int quantexp32(decimal32_t x) noexcept;
    constexpr int quantexp64(decimal64_t x) noexcept;
    constexpr int quantexp128(decimal128_t x) noexcept;

    } // namespace decimal
    } // namepsace boost

Effects: if x is finite, returns its quantum exponent.

Otherwise, `INT_MIN` is returned.

### `quantized`

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename Decimal>
    constexpr Decimal quantized(Decimal x, Decimal y) noexcept;

    constexpr decimal32_t quantized32(decimal32_t x, decimal32_t y) noexcept;
    constexpr decimal64_t quantized64(decimal64_t x, decimal64_t y) noexcept;
    constexpr decimal128_t quantized128(decimal128_t x, decimal128_t y) noexcept;

    } // namespace decimal
    } // namepsace boost

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 sNaN.

If one or both operands are NaN the result is sNaN.

Otherwise, if only one operand is infinity, the "invalid" floating-point exception is raised and the result is sNaN.

If both operands are infinity, the result is infinity, with the same sign as x.

The quantize functions do not signal underflow.

### `decompose`

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename Decimal>
    struct decimal_components
    {
        using significand_type = typename Decimal::significand_type;
        using biased_exponent_type = typename Decimal::biased_exponent_type;

        significand_type sig {};
        biased_exponent_type exp {};
        bool sign {};
    };

    template <typename Decimal>
    constexpr auto decompose(const Decimal value) noexcept -> decimal_components<Decimal>

    } // namespace decimal
    } // namespace boost

This function decomposes the input decimal value into a struct containing the significand, exponent, and sign. This function does not modify the stored value at all, so it returns the significand and exponent non-normalized i.e., in the cohort that they are stored in. For further discussion on normalized form see the page on cohorts.

### `frexp10`

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename Decimal>
    constexpr auto frexp10(Decimal num, int* expptr) noexcept;

    } // namespace decimal
    } // namepsace boost

This function is very similar to frexp, but returns the significand and an integral power of 10 since the `FLT_RADIX` of this type is 10. The significand is normalized to the number of digits of precision the type has (e.g. for decimal32_t it is [1'000'000, 9'999'999]). For further discussion on normalized form see the page on cohorts.

### `normalize`

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename Decimal>
    constexpr Decimal normalize(Decimal val) noexcept;

    } // namespace decimal
    } // namepsace boost

Similar to the `frexp10` function above, but rather than returning the normalized significand, and exponent of the Decimal number, it returns a normalized number. This removes the effects of cohorts on the IEEE 754 compliant types which for the example of `decimal32_t` means the significand will be in the range [1'000'000, 9'999'999]. This function has NO effect on fast types since they are always normalized internally.

Example 1. This example demonstrates the difference between `decompose`, `frexp10` and `normalize` on both IEEE and fast types.

    // Copyright 2026 Matt Borland
    // Distributed under the Boost Software License, Version 1.0.
    // https://www.boost.org/LICENSE_1_0.txt
    //
    // This file demonstrates the difference between decompose, frexp10 and
    // normalize, all of which inspect the internal representation of a
    // decimal floating point value but expose it in different ways.

    #include <boost/decimal/decimal32_t.hpp>    // For the type decimal32_t
    #include <boost/decimal/decimal_fast32_t.hpp>// For the type decimal_fast32_t
    #include <boost/decimal/cmath.hpp>          // For decompose, frexp10, normalize
    #include <boost/decimal/iostream.hpp>       // For decimal support for <iostream>
    #include <array>
    #include <iostream>

    template <typename Decimal>
    void show(const Decimal value)
    {
        // decompose returns the encoded significand, biased exponent and sign.
        // For IEEE types this preserves the cohort that was used at construction.
        // For fast types the value is normalized in the constructor, so the
        // components always reflect the normalized form.
        const auto components {boost::decimal::decompose(value)};

        // frexp10 returns the cohort-agnostic significand together with the
        // matching exponent written through the pointer argument. The significand
        // is normalized to the full precision of the type (for decimal32_t the
        // range is [1'000'000, 9'999'999]).
        int frexp_exp {};
        const auto frexp_sig {boost::decimal::frexp10(value, &frexp_exp)};

        // normalize returns a decimal of the same type whose representation has
        // had the cohort effects removed. For fast types this is a no-op since
        // they are already normalized.
        const auto normalized {boost::decimal::normalize(value)};

        std::cout << "  value      = " << value << '\n'
                  << "  decompose  : sig = " << components.sig
                  << ", exp = " << components.exp
                  << ", sign = " << components.sign << '\n'
                  << "  frexp10    : sig = " << frexp_sig
                  << ", exp = " << frexp_exp << '\n'
                  << "  normalize  = " << normalized << "\n\n";
    }

    int main()
    {
        // All three values compare equal but use different cohorts.
        constexpr std::array<boost::decimal::decimal32_t, 3> ieee_values {
            boost::decimal::decimal32_t{3, 2},
            boost::decimal::decimal32_t{300, 0},
            boost::decimal::decimal32_t{3000000, -4}
        };

        std::cout << "IEEE decimal32_t (cohort is preserved by the encoding):\n\n";
        for (const auto& v : ieee_values)
        {
            show(v);
        }

        // The same set of inputs given to a fast type all encode identically.
        constexpr std::array<boost::decimal::decimal_fast32_t, 3> fast_values {
            boost::decimal::decimal_fast32_t{3, 2},
            boost::decimal::decimal_fast32_t{300, 0},
            boost::decimal::decimal_fast32_t{3000000, -4}
        };

        std::cout << "decimal_fast32_t (always normalized internally):\n\n";
        for (const auto& v : fast_values)
        {
            show(v);
        }

        return 0;
    }

Output:

    IEEE decimal32_t (cohort is preserved by the encoding):

      value      = 300
      decompose  : sig = 3, exp = 2, sign = 0
      frexp10    : sig = 3000000, exp = -4
      normalize  = 300

      value      = 300
      decompose  : sig = 300, exp = 0, sign = 0
      frexp10    : sig = 3000000, exp = -4
      normalize  = 300

      value      = 300
      decompose  : sig = 3000000, exp = -4, sign = 0
      frexp10    : sig = 3000000, exp = -4
      normalize  = 300

    decimal_fast32_t (always normalized internally):

      value      = 300
      decompose  : sig = 3000000, exp = -4, sign = 0
      frexp10    : sig = 3000000, exp = -4
      normalize  = 300

      value      = 300
      decompose  : sig = 3000000, exp = -4, sign = 0
      frexp10    : sig = 3000000, exp = -4
      normalize  = 300

      value      = 300
      decompose  : sig = 3000000, exp = -4, sign = 0
      frexp10    : sig = 3000000, exp = -4
      normalize  = 300

### `rescale`

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename Decimal>
    constexpr Decimal rescale(Decimal val, int precision = 0);

    } // namespace decimal
    } // namespace boost

The function returns the decimal type with number of fractional digits equal to the value of precision. `rescale` is similar to trunc, and with the default precision argument of 0 it is identical.

| This function was previously known as `trunc_to` which was deprecated in v5.0.0 and removed in v6.0.0

### `comparetotal`

    #include <boost/decimal/cmath.hpp>

    namespace boost {
    namespace decimal {

    template <typename DecimalType>
    constexpr bool comparetotal(DecimalType x, DecimalType y) noexcept;

    } // namespace decimal
    } // namespace boost

This function is an extended version of normal ordering to take into account payloads of NANs, and canonical forms.

Effects:

1. If x < y returns `true`

2. If x > y returns `false`

3. If x == y:

   1. -0 < +0 is `true`

   2. +0 < -0 is `false`

   3. If x and y have the same sign:

      1. If x and y are both negative, `comparetotal(x, y)` is `true` IFF the exponent of x >= exponent of y

      2. Otherwise, `comparetotal(x, y)` is `true` IFF the exponent of x <= y

4. If x and y are unordered because x or y is a NAN:

   1. `comparetotal(-NAN, y)` is `true`

   2. `comparetotal(x, +NAN)` is `true`

   3. If x and y are both NAN:

      1. `comparetotal(-NAN, +NAN)` returns `true`

      2. `comparetotal(+SNAN, +QNAN)` returns `true`

      3. `comparetotal(-QNAN, -SNAN)` returns `true`

      4. `comparetotal(NAN, NAN)`

         1. If both `NAN` are positive returns `true` if the payload of `x` is less than the payload of `y`

         2. If both `NAN` are negative returns `true` if the payload of `x` is greater than the payload of `y`

Edit this Page