Note

The functionality described in this section is available only if mp++ was configured with the MPPP_WITH_QUADMATH option enabled (see the installation instructions).

New in version 0.5.

#include <mp++/real128.hpp>

## The real128 class¶

class real128

This class represents real values encoded in the quadruple-precision IEEE 754 floating-point format (which features up to 36 decimal digits of precision). The class is a thin wrapper around the __float128 type and the quadmath library, available in GCC and recent Clang versions on most modern platforms, on top of which it provides the following additions:

• interoperability with other mp++ classes,

• consistent behaviour with respect to the conventions followed elsewhere in mp++ (e.g., values are default-initialised to zero rather than to indefinite values, conversions must be explicit, etc.),

• enhanced compile-time (constexpr) capabilities,

• a generic C++ API.

This class has the look and feel of a C++ builtin type: it can interact with most of C++’s integral and floating-point primitive types (see the Real128CppInteroperable concept for the full list), integer and rational, and it provides overloaded operators. Differently from the builtin types, however, this class does not allow any implicit conversion to/from other types (apart from bool): construction from and conversion to primitive types must always be requested explicitly. As a side effect, syntax such as

real128 r = 5.23;
int m = r;


will not work, and direct initialization should be used instead:

real128 r{5.23};
int m{r};


Most of the functionality is exposed via plain functions, with the general convention that the functions are named after the corresponding quadmath functions minus the trailing q suffix. For instance, the quadmath code

__float128 a = 1;
auto b = ::sinq(a);


that computes the sine of 1 in quadruple precision, storing the result in b, becomes

real128 a{1};
auto b = sin(a);


where the sin() function is resolved via argument-dependent lookup.

Two ways of calling unary functions are usually provided:

• a unary free function returning the result of the operation,

• a nullary member function that modifies the calling object in-place.

For instance, here are two possible ways of computing the absolute value:

real128 r1, r2{-5};
r1 = abs(r2); // Unary abs(): returns the absolute value of r2, which is
// then assigned to r1.
r2.abs();     // Member function abs(): replaces the value of r2 with its
// absolute value.


Note that at this time a subset of the quadmath API has been wrapped by real128.

Various overloaded operators are provided. The common arithmetic operators (+, -, * and /) always return real128 as a result, promoting at most one operand to real128 before actually performing the computation. Similarly, the relational operators, ==, !=, <, >, <= and >= will promote at most one argument to real128 before performing the comparison. Alternative comparison functions treating NaNs specially are provided for use in the C++ standard library (and wherever strict weak ordering relations are needed).

The real128 class is a literal type, and, whenever possible, operations involving real128 are marked as constexpr. Some functions which are not constexpr in the quadmath library have been reimplemented as constexpr functions via compiler builtins.

Public Functions

constexpr real128()

Default constructor.

The default constructor will set this to zero.

constexpr real128(const real128 &other)

Trivial copy constructor.

Parameters
• other: the construction argument.

constexpr real128(real128 &&other)

Trivial move constructor.

Parameters
• other: the construction argument.

constexpr real128(__float128 x)

Constructor from a quadruple-precision floating-point value.

This constructor will initialise the internal value with x.

Parameters
• x: the quadruple-precision floating-point variable that will be used to initialise the internal value.

template<Real128CppInteroperable T>
constexpr real128(T x)

Constructor from interoperable C++ types.

This constructor will initialise the internal value with x.

Parameters
• x: the value that will be used for initialisation.

template<Real128MpppInteroperable T>
real128(const T &x)

Constructor from mp++ types.

This constructor will initialise the internal value with with the Real128MpppInteroperable x. Depending on the value of x, this may not be exactly equal to x after initialisation.

Parameters
• x: the value that will be used for the initialisation.

Exceptions
• std::overflow_error: if an overflow occurs during initialisation.

real128(const StringType &s)

Constructor from string.

This constructor will initialise p this from the StringType s. The accepted string formats are detailed in the quadmath library’s documentation (see the link below). Leading whitespaces are accepted (and ignored), but trailing whitespaces will raise an error.

Parameters
• s: the string that will be used to initialise this.

Exceptions
• std::invalid_argument: if s does not represent a valid quadruple-precision floating-point value.

• unspecified: any exception thrown by memory errors in standard containers.

real128(const char *begin, const char *end)

Constructor from range of characters.

This constructor will initialise this from the content of the input half-open range, which is interpreted as the string representation of a floating-point value.

Internally, the constructor will copy the content of the range to a local buffer, add a string terminator, and invoke the constructor from string.

Parameters
• begin: the begin of the input range.

• end: the end of the input range.

Exceptions
• unspecified: any exception thrown by the constructor from string or by memory errors in standard containers.

real128 &operator=(const real128 &other)

Trivial copy assignment operator.

Return

a reference to this.

Parameters
• other: the assignment argument.

real128 &operator=(real128 &&other)

Trivial move assignment operator.

Return

a reference to this.

Parameters
• other: the assignment argument.

constexpr real128 &operator=(const __float128 &x)

Assignment from a quadruple-precision floating-point value.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a reference to this.

Parameters
• x: the quadruple-precision floating-point variable that will be assigned to the internal value.

template<Real128CppInteroperable T>
constexpr real128 &operator=(const T &x)

Assignment from interoperable C++ types.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a reference to this.

Parameters
• x: the assignment argument.

template<Real128MpppInteroperable T>
real128 &operator=(const T &x)

Assignment from mp++ types.

The body of this operator is equivalent to:

return *this = real128{x};


That is, a temporary real128 is constructed from x and it is then move-assigned to this.

Return

a reference to this.

Parameters
• x: the assignment argument.

Exceptions
• unspecified: any exception thrown by the construction of a real128 from x.

real128 &operator=(const StringType &s)

Assignment from string.

The body of this operator is equivalent to:

return *this = real128{s};


That is, a temporary real128 is constructed from s and it is then move-assigned to this.

Return

a reference to this.

Parameters
• s: the string that will be used for the assignment.

Exceptions
• unspecified: any exception thrown by the constructor from string.

template<Real128CppInteroperable T>
constexpr operator T() const

Conversion operator to interoperable C++ types.

This operator will convert this to a Real128CppInteroperable type. The conversion uses a direct static_cast() of the internal m_value member to the target type, and thus no checks are performed to ensure that the value of this can be represented by the target type. Conversion to integral types will produce the truncated counterpart of this.

Return

this converted to T.

constexpr operator __float128() const

This operator will convert this to __float128.

Return

a copy of the quadruple-precision floating-point value stored internally.

template<Real128MpppInteroperable T>
operator T() const

Conversion operator to mp++ types.

This operator will convert this to a Real128MpppInteroperable type.

For conversions to integer, if this does not represent an integral value the conversion will yield the truncated counterpart of this.

For conversions to rational, the conversion, if successful, is exact.

Return

this converted to the target type.

Exceptions
• std::domain_error: if this represents a non-finite value.

template<Real128CppInteroperable T>
constexpr bool get(T &rop) const

Conversion method to interoperable C++ types.

This method will cast the m_value member to the Real128CppInteroperable type T, and assign the result to rop.

Note

This method is provided for consistency with other getter methods, and it does not offer any additional functionality over the plain conversion operator.

Note

This method is marked as constexpr only if at least C++14 is being used.

Return

always true.

Parameters
• rop: the variable which will store the result of the conversion.

template<Real128MpppInteroperable T>
bool get(T &rop) const

Conversion method to mp++ types.

This method, similarly to the corresponding conversion operator, will convert this to a Real128MpppInteroperable type, storing the result of the conversion into rop. Differently from the conversion operator, this method does not raise any exception: if the conversion is successful, the method will return true, otherwise the method will return false. If the conversion fails, rop will not be altered.

Return

true if the conversion succeeded, false otherwise. The conversion can fail only if this does not represent a finite value.

Parameters
• rop: the variable which will store the result of the conversion.

std::string to_string() const

Convert to string.

This method will convert this to a decimal string representation in scientific format. The number of significant digits in the output (36) guarantees that a real128 constructed from the returned string will have a value identical to the value of this.

The implementation uses the quadmath_snprintf() function from the quadmath library.

Return

a decimal string representation of this.

Exceptions
• std::runtime_error: if the internal call to the quadmath_snprintf() function fails.

std::tuple<std::uint_least8_t, std::uint_least16_t, std::uint_least64_t, std::uint_least64_t> get_ieee() const

Get the IEEE representation of the value.

This method will return a tuple containing the IEEE quadruple-precision floating-point representation of the value. The returned tuple elements are, in order:

• the sign of the value (1 for a negative sign bit, 0 for a positive sign bit),

• the exponent (a 15-bit unsigned value),

• the high part of the significand (a 48-bit unsigned value),

• the low part of the significand (a 64-bit unsigned value).

Return

a tuple containing the IEEE quadruple-precision floating-point representation of the value stored in this.

bool signbit() const

Sign bit.

This method will return the value of the sign bit of this. That is, if this is not a NaN the method will return true if this is negative, false otherwise. If this is NaN, the sign bit of the NaN value will be returned.

Return

true if the sign bit of this is set, false otherwise.

constexpr int fpclassify() const

Categorise the floating point value.

This method will categorise the floating-point value of this into the 5 categories, represented as int values, defined by the standard:

• FP_NAN for NaN,

• FP_INFINITE for infinite,

• FP_NORMAL for normal values,

• FP_SUBNORMAL for subnormal values,

• FP_ZERO for zero.

Return

the category to which the value of this belongs.

constexpr bool isnan() const

Detect NaN.

Return

true if this is NaN, false otherwise.

constexpr bool isinf() const

Detect infinity.

Return

true if this is infinite, false otherwise.

constexpr bool finite() const

Detect finite value.

Return

true if this is finite, false otherwise.

constexpr real128 &abs()

In-place absolute value.

This method will set this to its absolute value.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a reference to this.

real128 &sqrt()

In-place square root.

This method will set this to its nonnegative square root. If this is less than negative zero, the result will be NaN.

Return

a reference to this.

real128 &cbrt()

In-place cube root.

This method will set this to its real cube root.

Return

a reference to this.

real128 &sin()

In-place sine.

This method will set this to its sine.

Return

a reference to this.

real128 &cos()

In-place cosine.

This method will set this to its cosine.

Return

a reference to this.

real128 &tan()

In-place tangent.

This method will set this to its trigonometric tangent.

Return

a reference to this.

real128 &asin()

In-place inverse sine.

This method will set this to its inverse sine.

Return

a reference to this.

real128 &acos()

In-place inverse cosine.

This method will set this to its inverse cosine.

Return

a reference to this.

real128 &atan()

In-place inverse tangent.

This method will set this to its inverse trigonomotric tangent.

Return

a reference to this.

real128 &sinh()

In-place hyperbolic sine.

This method will set this to its hyperbolic sine.

Return

a reference to this.

real128 &cosh()

In-place hyperbolic cosine.

This method will set this to its hyperbolic cosine.

Return

a reference to this.

real128 &tanh()

In-place hyperbolic tangent.

This method will set this to its hyperbolic tangent.

Return

a reference to this.

real128 &asinh()

In-place inverse hyperbolic sine.

This method will set this to its inverse hyperbolic sine.

Return

a reference to this.

real128 &acosh()

In-place inverse hyperbolic cosine.

This method will set this to its inverse hyperbolic cosine.

Return

a reference to this.

real128 &atanh()

In-place inverse hyperbolic tangent.

This method will set this to its inverse hyperbolic tangent.

Return

a reference to this.

real128 &exp()

In-place natural exponential function.

This method will set this to $$\mathrm{e}$$ raised to the power of this.

Return

a reference to this.

real128 &log()

In-place natural logarithm.

This method will set this to its natural logarithm.

Return

a reference to this.

real128 &log10()

In-place base-10 logarithm.

This method will set this to its base-10 logarithm.

Return

a reference to this.

real128 &log2()

In-place base-2 logarithm.

This method will set this to its base-2 logarithm.

Return

a reference to this.

real128 &lgamma()

In-place lgamma function.

This method will set this to the value of the natural logarithm of its gamma function.

Return

a reference to this.

real128 &erf()

In-place error function.

This method will set this to the value of its error function.

Return

a reference to this.

Public Members

__float128 m_value

The internal value.

This class member gives direct access to the __float128 instance stored inside real128.

## Types¶

type __float128

A quadruple-precision floating-point type available in recent versions of the GCC and clang compilers. This is the type wrapped by the real128 class.

## Concepts¶

template<typename T>
concept mppp::Real128CppInteroperable

This concept is satisfied by fundamental C++ types that can interoperate with real128. Specifically:

template<typename T>
concept mppp::Real128MpppInteroperable

This concept is satisfied by mp++ types that can interoperate with real128. Specifically, the concept is satisfied if T is either integer or rational.

template<typename T, typename U>
concept mppp::Real128CppOpTypes

This concept is satisfied if the types T and U are suitable for use in the generic binary operators involving real128 and C++ types. Specifically, the concept will be true if either:

template<typename T, typename U>
concept mppp::Real128MpppOpTypes

This concept is satisfied if the types T and U are suitable for use in the generic binary operators involving real128 and mp++ types. Specifically, the concept will be true if one type is real128 and the other type satisfies Real128MpppInteroperable.

template<typename T, typename U>
concept mppp::Real128OpTypes

This concept is satisfied if the types T and U are suitable for use in the generic binary operators and functions involving real128. Specifically, the concept will be true if T and U satisfy Real128CppOpTypes or Real128MpppOpTypes.

## Functions¶

### Conversion¶

template<Real128CppInteroperable T>
constexpr bool mppp::get(T &rop, const real128 &x)

Conversion function to C++ types for real128.

This function will convert the input real128 x to a Real128CppInteroperable type, storing the result of the conversion into rop. The conversion is always successful.

Note

This function is provided for consistency with other getter functions, and it does not offer any additional functionality over the plain conversion operator.

Note

This function is marked as constexpr only if at least C++14 is being used.

Return

always true.

Parameters
• rop: the variable which will store the result of the conversion.

• x: the input real128.

real128 mppp::frexp(const real128 &x, int *exp)

Decompose a real128 into a normalized fraction and an integral power of two.

If x is zero, this function will return zero and store zero in exp. Otherwise, this function will return a real128 $$r$$ with an absolute value in the $$\left[0.5,1\right)$$ range, and it will store an integer value $$n$$ in exp such that $$r \times 2^n$$ equals to $$r$$. If x is a non-finite value, the return value will be x and an unspecified value will be stored in exp.

Return

the binary significand of x.

Parameters
• x: the input real128.

• exp: a pointer to the value that will store the exponent.

### Arithmetic¶

real128 mppp::fma(const real128 &x, const real128 &y, const real128 &z)

This function will return $$\left(x \times y\right) + z$$ as if calculated to infinite precision and rounded once.

Return

$$\left(x \times y\right) + z$$.

Parameters
• x: the first factor.

• y: the second factor.

• z: the addend.

constexpr real128 mppp::abs(const real128 &x)

Unary absolute value.

Return

the absolute value of x.

Parameters
• x: the real128 whose absolute value will be computed.

real128 mppp::scalbn(const real128 &x, int n)

Multiply by power of 2 (int overload).

Return

x multiplied by $$2^n$$.

Parameters
• x: the input real128.

• n: the power of 2 by which x will be multiplied.

real128 mppp::scalbln(const real128 &x, long n)

Multiply by power of 2 (long overload).

Return

x multiplied by $$2^n$$.

Parameters
• x: the input real128.

• n: the power of 2 by which x will be multiplied.

### Comparison¶

bool mppp::signbit(const real128 &x)

Sign bit of a real128.

Return

the sign bit of x (as returned by mppp::real128::signbit()).

Parameters
• x: the real128 whose sign bit will be returned.

constexpr int mppp::fpclassify(const real128 &x)

Categorise a real128.

Return

the category of the value of x, as established by mppp::real128::fpclassify().

Parameters
• x: the real128 whose floating-point category will be returned.

constexpr bool mppp::isnan(const real128 &x)

Detect if a real128 is NaN.

Return

true if x is NaN, false otherwise.

Parameters
• x: the real128 argument.

constexpr bool mppp::isinf(const real128 &x)

Detect if a real128 is infinite.

Return

true if x is infinite, false otherwise.

Parameters
• x: the real128 argument.

constexpr bool mppp::finite(const real128 &x)

Detect if a real128 is finite.

Return

true if x is finite, false otherwise.

Parameters
• x: the real128 argument.

constexpr bool mppp::real128_equal_to(const real128 &x, const real128 &y)

Equality predicate with special NaN handling for real128.

If both x and y are not NaN, this function is identical to the equality operator for real128. If at least one operand is NaN, this function will return true if both operands are NaN, false otherwise.

In other words, this function behaves like an equality operator which considers all NaN values equal to each other.

Return

true if $$x = y$$ (including the case in which both operands are NaN), false otherwise.

Parameters
• x: the first operand.

• y: the second operand.

constexpr bool mppp::real128_lt(const real128 &x, const real128 &y)

Less-than predicate with special NaN handling for real128.

If both x and y are not NaN, this function is identical to the less-than operator for real128. If at least one operand is NaN, this function will return true if x is not NaN, false otherwise.

In other words, this function behaves like a less-than operator which considers NaN values greater than non-NaN values. This function can be used as a comparator in various facilities of the standard library (e.g., std::sort(), std::set, etc.).

Return

true if $$x < y$$ (with NaN values considered greather than non-NaN values), false otherwise.

Parameters
• x: the first operand.

• y: the second operand.

constexpr bool mppp::real128_gt(const real128 &x, const real128 &y)

Greater-than predicate with special NaN handling for real128.

If both x and y are not NaN, this function is identical to the greater-than operator for real128. If at least one operand is NaN, this function will return true if y is not NaN, false otherwise.

In other words, this function behaves like a greater-than operator which considers NaN values greater than non-NaN values. This function can be used as a comparator in various facilities of the standard library (e.g., std::sort(), std::set, etc.).

Return

true if $$x > y$$ (with NaN values considered greather than non-NaN values), false otherwise.

Parameters
• x: the first operand.

• y: the second operand.

### Roots¶

real128 mppp::sqrt(real128 x)

Unary square root.

If x is less than negative zero, the result will be NaN.

Return

the nonnegative square root of x.

Parameters
• x: the real128 whose square root will be returned.

real128 mppp::cbrt(real128 x)

Unary cube root.

Return

the real cube root of x.

Parameters
• x: the real128 whose cube root will be returned.

real128 mppp::hypot(const real128 &x, const real128 &y)

Euclidean distance.

The calculation is performed without undue overflow or underflow during the intermediate steps of the calculation.

Return

the euclidean distance $$\sqrt{x^2+y^2}$$.

Parameters
• x: the first real128 argument.

• y: the second real128 argument.

### Exponentiation¶

template<typename T, typename U>requires Real128OpTypes<T, U> real128 mppp::pow(const T & x, const U & y)

Exponentiation.

This function will raise the base x to the exponent y. Internally, the implementation uses the powq() function from the quadmath library, after the conversion of one of the operands to real128 (if necessary).

Return

$$x^y$$.

Parameters
• x: the base.

• y: the exponent.

### Trigonometry¶

real128 mppp::sin(real128 x)

Unary sine.

Return

the sine of x.

Parameters
• x: the real128 whose sine will be computed.

real128 mppp::cos(real128 x)

Unary cosine.

Return

the cosine of x.

Parameters
• x: the real128 whose cosine will be computed.

real128 mppp::tan(real128 x)

Unary tangent.

Return

the tangent of x.

Parameters
• x: the real128 whose tangent will be computed.

real128 mppp::asin(real128 x)

Unary inverse sine.

Return

the inverse sine of x.

Parameters
• x: the real128 whose inverse sine will be computed.

real128 mppp::acos(real128 x)

Unary inverse cosine.

Return

the inverse cosine of x.

Parameters
• x: the real128 whose inverse cosine will be computed.

real128 mppp::atan(real128 x)

Unary inverse tangent.

Return

the inverse tangent of x.

Parameters
• x: the real128 whose inverse tangent will be computed.

### Hyperbolic functions¶

real128 mppp::sinh(real128 x)

Unary hyperbolic sine.

Return

the hyperbolic sine of x.

Parameters
• x: the real128 whose hyperbolic sine will be computed.

real128 mppp::cosh(real128 x)

Unary hyperbolic cosine.

Return

the hyperbolic cosine of x.

Parameters
• x: the real128 whose hyperbolic cosine will be computed.

real128 mppp::tanh(real128 x)

Unary hyperbolic tangent.

Return

the hyperbolic tangent of x.

Parameters
• x: the real128 whose hyperbolic tangent will be computed.

real128 mppp::asinh(real128 x)

Unary inverse hyperbolic sine.

Return

the inverse hyperbolic sine of x.

Parameters
• x: the real128 whose inverse hyperbolic sine will be computed.

real128 mppp::acosh(real128 x)

Unary inverse hyperbolic cosine.

Return

the inverse hyperbolic cosine of x.

Parameters
• x: the real128 whose inverse hyperbolic cosine will be computed.

real128 mppp::atanh(real128 x)

Unary inverse hyperbolic tangent.

Return

the inverse hyperbolic tangent of x.

Parameters
• x: the real128 whose inverse hyperbolic tangent will be computed.

### Logarithms and exponentials¶

real128 mppp::exp(real128 x)

Unary natural exponential function.

Return

$$\mathrm{e}$$ raised to the power of x.

Parameters
• x: the real128 whose natural exponential function be computed.

real128 mppp::log(real128 x)

Unary natural logarithm.

Return

the natural logarithm of x.

Parameters
• x: the real128 whose natural logarithm will be computed.

real128 mppp::log10(real128 x)

Unary base-10 logarithm.

Return

the base-10 logarithm of x.

Parameters
• x: the real128 whose base-10 logarithm will be computed.

real128 mppp::log2(real128 x)

Unary base-2 logarithm.

Return

the base-2 logarithm of x.

Parameters
• x: the real128 whose base-2 logarithm will be computed.

### Gamma functions¶

real128 mppp::lgamma(real128 x)

Natural logarithm of the gamma function.

Return

the lgamma of x.

Parameters
• x: the real128 whose lgamma will be computed.

### Other special functions¶

real128 mppp::erf(real128 x)

Error function.

Return

the erf of x.

Parameters
• x: the real128 whose erf will be computed.

### Floating-point manipulation¶

mppp::real128 nextafter(const mppp::real128 &from, const mppp::real128 &to)

New in version 0.14.

This function returns the next representable value of from in the direction of to.

If from equals to to, to is returned.

Parameters
• from – the real128 whose next representable value will be returned.

• to – the direction of the next representable value.

Returns

the next representable value of from in the direction of to.

### Input/Output¶

std::ostream &mppp::operator<<(std::ostream &os, const real128 &x)

Output stream operator.

This operator will print to the stream os the real128 x. The current implementation ignores any formatting flag specified in os, and the print format will be the one described in mppp::real128::to_string().

Warning

In future versions of mp++, the behaviour of this operator will change to support the output stream’s formatting flags. For the time being, users are encouraged to use the quadmath_snprintf() function from the quadmath library if precise and forward-compatible control on the printing format is needed.

Return

a reference to os.

Parameters
• os: the target stream.

• x: the input real128.

Exceptions

### Other¶

std::size_t mppp::hash(const mppp::real128 &x)

New in version 0.12.

Hash function for real128.

All NaN values produce the same hash value. For non-NaN arguments, this function guarantees that x == y implies hash(x) == hash(y).

Parameters

x – the argument.

Returns

a hash value for x.

## Mathematical operators¶

constexpr real128 mppp::operator+(real128 x)

Identity operator.

Return

a copy of x.

Parameters
• x: the real128 that will be copied.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> real128 mppp::operator+(const T & x, const U & y)

Binary addition involving real128 and C++ types.

Return

$$x + y$$.

Parameters
• x: the first operand.

• y: the second operand.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> T& mppp::operator+=(T & x, const U & y)

In-place addition involving real128 and C++ types.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a reference to x, after it has been incremented by y.

Parameters
• x: the augend.

• y: the addend.

constexpr real128 &mppp::operator++(real128 &x)

Prefix increment.

This operator will increment x by one.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a reference to x after the increment.

Parameters
• x: the real128 that will be increased.

constexpr real128 mppp::operator++(real128 &x, int)

Suffix increment.

This operator will increment x by one and return a copy of x as it was before the increment.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a copy of x before the increment.

Parameters
• x: the real128 that will be increased.

constexpr real128 mppp::operator-(const real128 &x)

Negation operator.

Return

$$-x$$.

Parameters
• x: the real128 whose opposite will be returned.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> real128 mppp::operator-(const T & x, const U & y)

Binary subtraction involving real128 and C++ types.

Return

$$x - y$$.

Parameters
• x: the first operand.

• y: the second operand.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> T& mppp::operator-=(T & x, const U & y)

In-place subtraction involving real128 and C++ types.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a reference to x, after it has been decremented by y.

Parameters
• x: the minuend.

• y: the subtrahend.

constexpr real128 &mppp::operator--(real128 &x)

Prefix decrement.

This operator will decrement x by one.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a reference to x after the decrement.

Parameters
• x: the real128 that will be decreased.

constexpr real128 mppp::operator--(real128 &x, int)

Suffix decrement.

This operator will decrement x by one and return a copy of x as it was before the decrement.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a copy of x before the decrement.

Parameters
• x: the real128 that will be decreased.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> real128 mppp::operator*(const T & x, const U & y)

Binary multiplication involving real128 and C++ types.

Return

$$x \times y$$.

Parameters
• x: the first operand.

• y: the second operand.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> T& mppp::operator*=(T & x, const U & y)

In-place multiplication involving real128 and C++ types.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a reference to x, after it has been multiplied by y.

Parameters
• x: the multiplicand.

• y: the multiplicator.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> real128 mppp::operator/(const T & x, const U & y)

Binary division involving real128 and C++ types.

Return

$$x / y$$.

Parameters
• x: the first operand.

• y: the second operand.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> T& mppp::operator/=(T & x, const U & y)

In-place division involving real128 and C++ types.

Note

This operator is marked as constexpr only if at least C++14 is being used.

Return

a reference to x, after it has been divided by y.

Parameters
• x: the dividend.

• y: the divisor.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> bool mppp::operator==(const T & x, const U & y)

Equality operator involving real128 and C++ types.

The implementation uses the comparison operator of the __float128 type.

Note

This operator does not handle NaN in a special way (that is, NaN compares different from any value, including NaN itself). See mppp::real128_equal_to() for an equality predicate that handles NaN specially.

Return

true if $$x = y$$, false otherwise.

Parameters
• x: the first operand.

• y: the second operand.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> bool mppp::operator!=(const T & x, const U & y)

Inequality operator involving real128 and C++ types.

The implementation uses the comparison operator of the __float128 type.

Note

This operator does not handle NaN in a special way (that is, NaN compares different from any value, including NaN itself). See mppp::real128_equal_to() for an equality predicate that handles NaN specially.

Return

true if $$x = y$$, false otherwise.

Parameters
• x: the first operand.

• y: the second operand.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> bool mppp::operator<(const T & x, const U & y)

Less-than operator involving real128 and C++ types.

The implementation uses the less-than operator of the __float128 type.

Note

This operator does not handle NaN in a special way (that is, NaN is never less than any value, and no value is less than NaN). See mppp::real128_lt() for a less-than predicate that handles NaN specially.

Return

true if $$x < y$$, false otherwise.

Parameters
• x: the first operand.

• y: the second operand.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> bool mppp::operator<=(const T & x, const U & y)

Less-than or equal operator involving real128 and C++ types.

The implementation uses the less-than or equal operator of the __float128 type.

Note

This operator does not handle NaN in a special way (that is, NaN is never less than or equal to any value, and no value is less than or equal to NaN).

Return

true if $$x \leq y$$, false otherwise.

Parameters
• x: the first operand.

• y: the second operand.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> bool mppp::operator>(const T & x, const U & y)

Greater-than operator involving real128 and C++ types.

The implementation uses the greater-than operator of the __float128 type.

Note

This operator does not handle NaN in a special way (that is, NaN is never greater than any value, and no value is greater than NaN). See mppp::real128_gt() for a greater-than predicate that handles NaN specially.

Return

true if $$x > y$$, false otherwise.

Parameters
• x: the first operand.

• y: the second operand.

template<typename T, typename U>requires constexpr Real128CppOpTypes<T, U> bool mppp::operator>=(const T & x, const U & y)

Greater-than or equal operator involving real128 and C++ types.

The implementation uses the greater-than or equal operator of the __float128 type.

Note

This operator does not handle NaN in a special way (that is, NaN is never greater than or equal to any value, and no value is greater than or equal to NaN).

Return

true if $$x \geq y$$, false otherwise.

Parameters
• x: the first operand.

• y: the second operand.

## Constants¶

A few mathematical constants are provided. The constants are available as inline variables (e.g., mppp::pi_128, requires C++17 or later) and as constexpr functions (e.g., mppp::real128_pi(), always available). Inline variables and constexpr functions provide exactly the same functionality, but inline variables are more convenient if C++17 is an option.

Note

Some of these constants are also available as macros from the quadmath library.

constexpr unsigned mppp::sig_digits_128 = real128_sig_digits()

The number of binary digits in the significand of a real128 (113).

constexpr real128 mppp::max_128 = real128_max()

The largest positive finite value representable by real128.

constexpr real128 mppp::min_128 = real128_min()

The smallest positive value representable by real128 with full precision.

constexpr real128 mppp::epsilon_128 = real128_epsilon()

The difference between 1 and the next larger representable number by real128.

constexpr real128 mppp::denorm_min_128 = real128_denorm_min()

The smallest positive denormalized number representable by real128.

constexpr real128 mppp::inf_128 = real128_inf()

Quadruple-precision $$+\infty$$ constant.

constexpr real128 mppp::nan_128 = real128_nan()

constexpr real128 mppp::pi_128 = real128_pi()

Quadruple-precision $$\pi$$ constant.

constexpr real128 mppp::e_128 = real128_e()

Quadruple-precision $$\mathrm{e}$$ constant (Euler’s number).

constexpr real128 mppp::sqrt2_128 = real128_sqrt2()

Quadruple-precision $$\sqrt{2}$$ constant.

constexpr unsigned mppp::real128_sig_digits()

The number of binary digits in the significand of a real128.

Return

the integral constant 113.

constexpr real128 mppp::real128_max()

The largest positive finite value representable by real128.

Return

approximately $$1.18973 \times 10^{4932}$$.

constexpr real128 mppp::real128_min()

The smallest positive value representable by real128 with full precision.

Return

approximately $$3.3621 \times 10^{-4932}$$.

constexpr real128 mppp::real128_epsilon()

The difference between 1 and the next larger number representable by real128.

Return

$$2^{-112}$$.

constexpr real128 mppp::real128_denorm_min()

The smallest positive denormalized number representable by real128.

Return

$$2^{-16494}$$.

constexpr real128 mppp::real128_inf()

The positive $$\infty$$ constant.

Return

$$+\infty$$.

constexpr real128 mppp::real128_nan()

NaN constant.

Return

a quiet NaN value with unspecified sign bit.

constexpr real128 mppp::real128_pi()

The $$\pi$$ constant.

Return

the quadruple-precision value of $$\pi$$.

constexpr real128 mppp::real128_e()

The $$\mathrm{e}$$ constant (Euler’s number).

Return

the quadruple-precision value of $$\mathrm{e}$$.

constexpr real128 mppp::real128_sqrt2()

The $$\sqrt{2}$$ constant.

Return

the quadruple-precision value of $$\sqrt{2}$$.

## Standard library specialisations¶

template<>
class std::numeric_limits<mppp::real128>

This specialisation exposes the compile-time properties of real128 as specified by the C++ standard.

static constexpr bool is_specialized = true
static constexpr int digits = 113
static constexpr int digits10 = 33
static constexpr int max_digits10 = 36
static constexpr bool is_signed = true
static constexpr bool is_integer = false
static constexpr bool is_exact = false
static constexpr int radix = 2
static constexpr int min_exponent = -16381
static constexpr int min_exponent10 = -4931
static constexpr int max_exponent = 16384
static constexpr int max_exponent10 = 4931
static constexpr bool has_infinity = true
static constexpr bool has_quiet_NaN = true
static constexpr bool has_signaling_NaN = false
static constexpr std::float_denorm_style has_denorm = std::denorm_present
static constexpr bool has_denorm_loss = true
static constexpr bool is_iec559 = true
static constexpr bool is_bounded = false
static constexpr bool is_modulo = false
static constexpr bool traps = false
static constexpr bool tinyness_before = false
static constexpr std::float_round_style round_style = std::round_to_nearest
static constexpr mppp::real128 min()
Returns

the output of mppp::real128_min().

static constexpr mppp::real128 max()
Returns

the output of mppp::real128_max().

static constexpr mppp::real128 lowest()
Returns

the negative of the output of mppp::real128_max().

static constexpr mppp::real128 epsilon()
Returns

the output of mppp::real128_epsilon().

static constexpr mppp::real128 round_error()
Returns

0.5.

static constexpr mppp::real128 infinity()
Returns

the output of mppp::real128_inf().

static constexpr mppp::real128 quiet_NaN()
Returns

the output of mppp::real128_nan().

static constexpr mppp::real128 signaling_NaN()
Returns

0.

static constexpr mppp::real128 denorm_min()
Returns

the output of mppp::real128_denorm_min().