decimal64_t
Description
decimal64_t is the 64-bit version of the decimal interchange format, and has the following properties as defined in IEEE 754-2019 table 3.6
Attribute |
values |
Storage Width |
64 bits |
Precision |
16 decimal digits |
Max exponent |
385 |
Max Value |
9.999999999999999e+385 |
Smallest Normalized Value |
1.000000000000000e-382 |
Smallest Subnormal Value |
1e-398 |
Prior to v5.0.0 this type was known as decimal64.
This name has been removed in v6.0.0.
|
The encoding of decimal64_t is in the BID format.
#include <boost/decimal/decimal64_t.hpp>
namespace boost {
namespace decimal {
class decimal64_t {
public:
using significand_type = std::uint64_t;
using exponent_type = std::uint32_t;
using biased_exponent_type = std::int32_t;
// Paragraph numbers are from ISO/IEC DTR 24733
// 3.2.3.1 construct/copy/destroy
constexpr decimal64_t() noexcept = default;
// 3.2.2.2 Conversion form floating-point type
template <typename Float>
explicit BOOST_DECIMAL_CXX20_CONSTEXPR decimal64_t(Float val) noexcept;
// 3.2.3.3 Conversion from integral type
template <typename Integer>
explicit constexpr decimal64_t(Integer val) noexcept;
// Extension: Construction from (c)string
explicit constexpr decimal64_t(const char* str);
#ifndef BOOST_DECIMAL_HAS_STD_STRING_VIEW
explicit inline decimal64_t(const std::string& str);
#else
explicit constexpr decimal64_t(std::string_view str);
#endif
template <typename UnsignedIntegral, typename Integral>
constexpr decimal64_t(UnsignedIntegral coeff, Integral exp, bool is_negative = false) noexcept;
template <typename SignedIntegral, typename Integral>
constexpr decimal64_t(SignedIntegral coeff, Integral exp) noexcept;
template <typename Integral>
constexpr decimal64_t& operator=(const Integeral& RHS) noexcept;
// 3.2.3.4 Conversion to integral type
// If the value exceeds the range of the integral,
// or is non-finite std::numeric_limits::max() is returned
explicit constexpr operator int() const noexcept;
explicit constexpr operator unsigned() const noexcept;
explicit constexpr operator long() const noexcept;
explicit constexpr operator unsigned long() const noexcept;
explicit constexpr operator long long() const noexcept;
explicit constexpr operator unsigned long long() const noexcept;
// 3.2.3.5 increment and decrement operators:
constexpr decimal64_t& operator++();
constexpr decimal64_t operator++(int);
constexpr decimal64_t& operator--();
constexpr decimal64_t operator--(int);
// 3.2.3.6 compound assignment:
constexpr decimal64_t& operator+=(RHS rhs);
constexpr decimal64_t& operator-=(RHS rhs);
constexpr decimal64_t& operator*=(RHS rhs);
constexpr decimal64_t& operator/=(RHS rhs);
// 3.2.6 Conversion to floating-point type
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator float() const noexcept;
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator double() const noexcept;
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator long double() const noexcept;
// The following are available assuming a C++23 compiler that provides the header <stdfloat>
explicit constexpr operator std::float16_t() const noexcept;
explicit constexpr operator std::float32_t() const noexcept;
explicit constexpr operator std::float64_t() const noexcept;
explicit constexpr operator std::bfloat16_t() const noexcept;
explicit constexpr operator decimal32_t() const noexcept;
explicit constexpr operator decimal_fast32_t() const noexcept;
explicit constexpr operator decimal_fast64_t() const noexcept;
explicit constexpr operator decimal128_t() const noexcept;
explicit constexpr operator decimal_fast128_t() const noexcept;
}; // class decimal64_t
} //namespace decimal
} //namespace boost
Operator Behavior
Construction to and from binary floating-point type
// 3.2.2.2 Conversion from floating-point type
template <typename Float>
explicit BOOST_DECIMAL_CXX20_CONSTEXPR decimal64_t(Float val) noexcept;
// 3.2.6 Conversion to floating-point type
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator float() const noexcept;
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator double() const noexcept;
explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator long double() const noexcept;
// If C++23 and <stdfloat> are available
explicit constexpr operator std::float16_t() const noexcept;
explicit constexpr operator std::float32_t() const noexcept;
explicit constexpr operator std::float64_t() const noexcept;
explicit constexpr operator std::bfloat16_t() const noexcept;
Construction From Integral Type
// 3.2.2.3 Conversion from integral type
template <typename Integer>
explicit constexpr decimal64_t(Integer val) noexcept;
Constructs a decimal value subject to the current rounding mode (if necessary).
Construction From String
// Extension: Construction from (c)string
explicit constexpr decimal64_t(const char* str);
#ifndef BOOST_DECIMAL_HAS_STD_STRING_VIEW
explicit inline decimal64_t(const std::string& str);
#else
explicit constexpr decimal64_t(std::string_view str);
#endif
Constructs a decimal value that matches str subject to:
-
If
stris anullptror of length 0 either:-
throw std::runtime_error -
Constructs a
QNANin a no exception environment
-
-
If
stris an invalid string either:-
throw std::runtime_error -
Constructs a
QNANin a no exception environment
-
-
On overflow constructs
INF -
On underflow constructs
0 -
Rounds value represented by
straccording to current rounding mode
Conversion to Integral Type
// 3.2.2.4 Conversion to integral type
explicit constexpr operator int() const noexcept;
explicit constexpr operator unsigned() const noexcept;
explicit constexpr operator long() const noexcept;
explicit constexpr operator unsigned long() const noexcept;
explicit constexpr operator long long() const noexcept;
explicit constexpr operator unsigned long long() const noexcept;
Constructs an integer representation of the decimal value subject to:
-
If the decimal value is
INFreturnsstd::numeric_limits<IntegerType>::max() -
If the decimal value is
NANreturnsstd::numeric_limits<IntegerType>::max() -
If the decimal value exceeds the range of the
IntegerTypereturnsstd::numeric_limits<IntegerType>::max()
Increment and Decrement Operators
// 3.2.2.5 increment and decrement operators:
constexpr decimal64_t& operator++();
constexpr decimal64_t operator++(int);
constexpr decimal64_t& operator--();
constexpr decimal64_t operator--(int);
Increments/Decrements the decimal value subject to:
-
If the decimal value is
NANreturnsQNAN -
If the decimal value is
INFreturnsINF
Compound Operators
// 3.2.2.6 compound assignment:
constexpr decimal64_t& operator+=(RHS rhs);
constexpr decimal64_t& operator-=(RHS rhs);
constexpr decimal64_t& operator*=(RHS rhs);
constexpr decimal64_t& operator/=(RHS rhs);
Matches the behavior of addition, subtraction, multiplication, and division.
Conversion to Other Decimal Types
explicit constexpr operator decimal32_t() const noexcept;
explicit constexpr operator decimal_fast32_t() const noexcept;
explicit constexpr operator decimal_fast64_t() const noexcept;
explicit constexpr operator decimal128_t() const noexcept;
explicit constexpr operator decimal_fast128_t() const noexcept;
Conversion to decimal32_t or `decimal_fast32_t is subject to:
-
Current rounding mode if the number of digits exceeds the precision of
decimal32_t -
Overflow constructs
INF -
Underflow constructs
0
Conversion to all other decimal types is lossless in all cases.
Non-Member Operator Behavior
See here for behavior of non-member operators.