Quadrupleprecision floats¶
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
¶ Quadrupleprecision floatingpoint class.
This class represents real values encoded in the quadrupleprecision IEEE 754 floatingpoint 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 defaultinitialised to zero rather than to indefinite values, conversions must be explicit, etc.),
enhanced compiletime (
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 floatingpoint primitive types (see the
Real128CppInteroperable
concept for the full list),integer
andrational
, and it provides overloaded operators. Differently from the builtin types, however, this class does not allow any implicit conversion to/from other types (apart frombool
): construction from and conversion to primitive types must always be requested explicitly. As a side effect, syntax such asreal128 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
, becomesreal128 a{1}; auto b = sin(a);
where the
sin()
function is resolved via argumentdependent 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 inplace.
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 returnreal128
as a result, promoting at most one operand toreal128
before actually performing the computation. Similarly, the relational operators,==
,!=
,<
,>
,<=
and>=
will promote at most one argument toreal128
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 involvingreal128
are marked asconstexpr
. Some functions which are notconstexpr
in the quadmath library have been reimplemented asconstexpr
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 quadrupleprecision floatingpoint value.
This constructor will initialise the internal value with
x
. Parameters
x
: the quadrupleprecision floatingpoint variable that will be used to initialise the internal value.

template<Real128CppInteroperable
T
>
constexprreal128
(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 ofx
,this
may not be exactly equal tox
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 initialisethis
.
 Exceptions
std::invalid_argument
: ifs
does not represent a valid quadrupleprecision floatingpoint 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 halfopen range, which is interpreted as the string representation of a floatingpoint 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 quadrupleprecision floatingpoint 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 quadrupleprecision floatingpoint 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 fromx
and it is then moveassigned tothis
. Return
a reference to
this
. Parameters
x
: the assignment argument.
 Exceptions
unspecified
: any exception thrown by the construction of a real128 fromx
.

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 froms
and it is then moveassigned tothis
. 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
>
constexproperator T
() const¶ Conversion operator to interoperable C++ types.
This operator will convert
this
to aReal128CppInteroperable
type. The conversion uses a directstatic_cast()
of the internalm_value
member to the target type, and thus no checks are performed to ensure that the value ofthis
can be represented by the target type. Conversion to integral types will produce the truncated counterpart ofthis
. Return
this
converted toT
.

constexpr
operator __float128
() const¶ Conversion to quadrupleprecision floatingpoint.
This operator will convert
this
to__float128
. Return
a copy of the quadrupleprecision floatingpoint value stored internally.

template<Real128MpppInteroperable
T
>operator T
() const¶ Conversion operator to mp++ types.
This operator will convert
this
to aReal128MpppInteroperable
type.For conversions to
integer
, ifthis
does not represent an integral value the conversion will yield the truncated counterpart ofthis
.For conversions to
rational
, the conversion, if successful, is exact. Return
this
converted to the target type. Exceptions
std::domain_error
: ifthis
represents a nonfinite value.

template<Real128CppInteroperable
T
>
constexpr boolget
(T &rop) const¶ Conversion method to interoperable C++ types.
This method will cast the
m_value
member to theReal128CppInteroperable
type T, and assign the result torop
.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
>
boolget
(T &rop) const¶ Conversion method to mp++ types.
This method, similarly to the corresponding conversion operator, will convert
this
to aReal128MpppInteroperable
type, storing the result of the conversion intorop
. Differently from the conversion operator, this method does not raise any exception: if the conversion is successful, the method will returntrue
, otherwise the method will returnfalse
. If the conversion fails,rop
will not be altered. Return
true
if the conversion succeeded,false
otherwise. The conversion can fail only ifthis
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 areal128
constructed from the returned string will have a value identical to the value ofthis
.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 thequadmath_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 quadrupleprecision floatingpoint 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 15bit unsigned value),
the high part of the significand (a 48bit unsigned value),
the low part of the significand (a 64bit unsigned value).
 Return
a tuple containing the IEEE quadrupleprecision floatingpoint 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, ifthis
is not a NaN the method will returntrue
ifthis
is negative,false
otherwise. Ifthis
is NaN, the sign bit of the NaN value will be returned. Return
true
if the sign bit ofthis
is set,false
otherwise.

constexpr int
fpclassify
() const¶ Categorise the floating point value.
This method will categorise the floatingpoint value of
this
into the 5 categories, represented asint
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
ifthis
is NaN,false
otherwise.

constexpr bool
isinf
() const¶ Detect infinity.
 Return
true
ifthis
is infinite,false
otherwise.

constexpr bool
finite
() const¶ Detect finite value.
 Return
true
ifthis
is finite,false
otherwise.

constexpr real128 &
abs
()¶ Inplace 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
()¶ Inplace square root.
This method will set
this
to its nonnegative square root. Ifthis
is less than negative zero, the result will be NaN. Return
a reference to
this
.

real128 &
cbrt
()¶ Inplace cube root.
This method will set
this
to its real cube root. Return
a reference to
this
.

real128 &
cos
()¶ Inplace cosine.
This method will set
this
to its cosine. Return
a reference to
this
.

real128 &
tan
()¶ Inplace tangent.
This method will set
this
to its trigonometric tangent. Return
a reference to
this
.

real128 &
asin
()¶ Inplace inverse sine.
This method will set
this
to its inverse sine. Return
a reference to
this
.

real128 &
acos
()¶ Inplace inverse cosine.
This method will set
this
to its inverse cosine. Return
a reference to
this
.

real128 &
atan
()¶ Inplace inverse tangent.
This method will set
this
to its inverse trigonomotric tangent. Return
a reference to
this
.

real128 &
sinh
()¶ Inplace hyperbolic sine.
This method will set
this
to its hyperbolic sine. Return
a reference to
this
.

real128 &
cosh
()¶ Inplace hyperbolic cosine.
This method will set
this
to its hyperbolic cosine. Return
a reference to
this
.

real128 &
tanh
()¶ Inplace hyperbolic tangent.
This method will set
this
to its hyperbolic tangent. Return
a reference to
this
.

real128 &
asinh
()¶ Inplace inverse hyperbolic sine.
This method will set
this
to its inverse hyperbolic sine. Return
a reference to
this
.

real128 &
acosh
()¶ Inplace inverse hyperbolic cosine.
This method will set
this
to its inverse hyperbolic cosine. Return
a reference to
this
.

real128 &
atanh
()¶ Inplace inverse hyperbolic tangent.
This method will set
this
to its inverse hyperbolic tangent. Return
a reference to
this
.

real128 &
exp
()¶ Inplace natural exponential function.
This method will set
this
to \( \mathrm{e} \) raised to the power ofthis
. Return
a reference to
this
.

real128 &
log
()¶ Inplace natural logarithm.
This method will set
this
to its natural logarithm. Return
a reference to
this
.

real128 &
log10
()¶ Inplace base10 logarithm.
This method will set
this
to its base10 logarithm. Return
a reference to
this
.

real128 &
log2
()¶ Inplace base2 logarithm.
This method will set
this
to its base2 logarithm. Return
a reference to
this
.
Public Members

__float128
m_value
¶ The internal value.
This class member gives direct access to the
__float128
instance stored insidereal128
.
Types¶
Concepts¶

template<typename
T
>
conceptmppp
::
Real128CppInteroperable
¶ This concept is satisfied by fundamental C++ types that can interoperate with
real128
. Specifically:on GCC, this concept is satisfied by the types satisfying
mppp::CppInteroperable
;on Clang, this concept is satisfied by the types satisfying
mppp::CppInteroperable
, minuslong double
.

template<typename
T
>
conceptmppp
::
Real128MpppInteroperable
¶ This concept is satisfied by mp++ types that can interoperate with
real128
. Specifically, the concept is satisfied ifT
is eitherinteger
orrational
.

template<typename
T
, typenameU
>
conceptmppp
::
Real128CppOpTypes
¶ This concept is satisfied if the types
T
andU
are suitable for use in the generic binary operators involvingreal128
and C++ types. Specifically, the concept will betrue
if either:T
andU
are bothreal128
, orone type is
real128
and the other is aReal128CppInteroperable
type.

template<typename
T
, typenameU
>
conceptmppp
::
Real128MpppOpTypes
¶ This concept is satisfied if the types
T
andU
are suitable for use in the generic binary operators involvingreal128
and mp++ types. Specifically, the concept will betrue
if one type isreal128
and the other type satisfiesReal128MpppInteroperable
.

template<typename
T
, typenameU
>
conceptmppp
::
Real128OpTypes
¶ This concept is satisfied if the types
T
andU
are suitable for use in the generic binary operators and functions involvingreal128
. Specifically, the concept will betrue
ifT
andU
satisfyReal128CppOpTypes
orReal128MpppOpTypes
.
Functions¶
Conversion¶

template<Real128CppInteroperable
T
>
constexpr boolmppp
::
get
(T &rop, const real128 &x)¶ Conversion function to C++ types for real128.
This function will convert the input
real128
x
to aReal128CppInteroperable
type, storing the result of the conversion intorop
. 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 inexp
. Otherwise, this function will return areal128
\(r\) with an absolute value in the \(\left[0.5,1\right)\) range, and it will store an integer value \(n\) inexp
such that \(r \times 2^n\) equals to \(r\). Ifx
is a nonfinite value, the return value will bex
and an unspecified value will be stored inexp
. 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)¶ Fused multiplyadd.
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.
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 floatingpoint category will be returned.

constexpr bool
mppp
::
isnan
(const real128 &x)¶ Detect if a real128 is NaN.
 Return
true
ifx
is NaN,false
otherwise. Parameters
x
: the real128 argument.

constexpr bool
mppp
::
isinf
(const real128 &x)¶ Detect if a real128 is infinite.
 Return
true
ifx
is infinite,false
otherwise. Parameters
x
: the real128 argument.

constexpr bool
mppp
::
finite
(const real128 &x)¶ Detect if a real128 is finite.
 Return
true
ifx
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
andy
are not NaN, this function is identical to the equality operator forreal128
. If at least one operand is NaN, this function will returntrue
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)¶ Lessthan predicate with special NaN handling for real128.
If both
x
andy
are not NaN, this function is identical to the lessthan operator forreal128
. If at least one operand is NaN, this function will returntrue
ifx
is not NaN,false
otherwise.In other words, this function behaves like a lessthan operator which considers NaN values greater than nonNaN 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 nonNaN values),false
otherwise. Parameters
x
: the first operand.y
: the second operand.

constexpr bool
mppp
::
real128_gt
(const real128 &x, const real128 &y)¶ Greaterthan predicate with special NaN handling for real128.
If both
x
andy
are not NaN, this function is identical to the greaterthan operator forreal128
. If at least one operand is NaN, this function will returntrue
ify
is not NaN,false
otherwise.In other words, this function behaves like a greaterthan operator which considers NaN values greater than nonNaN 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 nonNaN 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.
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 exponenty
. Internally, the implementation uses thepowq()
function from the quadmath library, after the conversion of one of the operands toreal128
(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.
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.
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.
Gamma functions¶
Other special functions¶
Floatingpoint 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
thereal128
x
. The current implementation ignores any formatting flag specified inos
, and the print format will be the one described inmppp::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 forwardcompatible control on the printing format is needed. Return
a reference to
os
. Parameters
os
: the target stream.x
: the input real128.
 Exceptions
unspecified
: any exception thrown by real128::to_string().
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)
Inplace 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 byy
. 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 ofx
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)
Inplace 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 byy
. 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 ofx
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)
Inplace 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 byy
. 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)
Inplace 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 byy
. 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)
Lessthan operator involving real128 and C++ types.
The implementation uses the lessthan 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 lessthan 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)
Lessthan or equal operator involving real128 and C++ types.
The implementation uses the lessthan 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)
Greaterthan operator involving real128 and C++ types.
The implementation uses the greaterthan 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 greaterthan 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)
Greaterthan or equal operator involving real128 and C++ types.
The implementation uses the greaterthan 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()¶ Quadrupleprecision \( +\infty \) constant.

constexpr real128
mppp
::
nan_128
= real128_nan()¶ Quadrupleprecision quiet NaN constant.

constexpr real128
mppp
::
pi_128
= real128_pi()¶ Quadrupleprecision \( \pi \) constant.

constexpr real128
mppp
::
e_128
= real128_e()¶ Quadrupleprecision \( \mathrm{e} \) constant (Euler’s number).

constexpr real128
mppp
::
sqrt2_128
= real128_sqrt2()¶ Quadrupleprecision \( \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_nan
()¶ NaN constant.
 Return
a quiet NaN value with unspecified sign bit.

constexpr real128
mppp
::
real128_pi
()¶ The \( \pi \) constant.
 Return
the quadrupleprecision value of \( \pi \).
Standard library specialisations¶

template<>
classstd
::
numeric_limits
<mppp::real128>¶ This specialisation exposes the compiletime 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
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
denorm_min
()¶  Returns
the output of
mppp::real128_denorm_min()
.

static constexpr bool