Ensure that numeric_traits<Scalar_T>::promoted::type always has at least as many mantissa bits as Scalar_T, and numeric_traits<Scalar_T>::demoted::type has at most as many mantissa bits as Scalar_T.
If long double has the same number of mantissa bits as double, promote as: float -> double -> dd_real -> qd_real, long double -> dd_real, and demote as: qd_real -> dd_real -> double -> float, long double -> float.
If long double has more mantissa bits than dd_real, promote as: float -> double -> dd_real -> long double -> qd_real, and demote as: qd_real -> long double -> dd_real -> double -> float.
Otherwise, continue to promote as: float -> double -> long double -> dd_real -> qd_real, and demote as: qd_real -> dd_real -> long double -> double -> float.
Ensure that
numeric_traits<Scalar_T>::promoted::type
always has at least as many mantissa bits asScalar_T
, andnumeric_traits<Scalar_T>::demoted::type
has at most as many mantissa bits asScalar_T
.See https://en.cppreference.com/w/cpp/language/types . The C++
float
anddouble
types are usually based on the IEEE 754 32 bit and 64 bit floating point standards. In contrast, thelong double
type can be anywhere from 64 bits (as IEEE 754 64 bit floating point) to 128 bits (as IEEE 754 128 bit floating point). The 128 bit format has a precision of 113 bits, but thedd_real
format has a precision of only 106 bits.If
long double
has the same number of mantissa bits asdouble
, promote as:float -> double -> dd_real -> qd_real
,long double -> dd_real
, and demote as:qd_real -> dd_real -> double -> float
,long double -> float
.If
long double
has more mantissa bits thandd_real
, promote as:float -> double -> dd_real -> long double -> qd_real
, and demote as:qd_real -> long double -> dd_real -> double -> float
.Otherwise, continue to promote as:
float -> double -> long double -> dd_real -> qd_real
, and demote as:qd_real -> dd_real -> long double -> double -> float
.