|
| 1 | +//// |
| 2 | +Copyright 2024 Matt Borland |
| 3 | +Distributed under the Boost Software License, Version 1.0. |
| 4 | +https://www.boost.org/LICENSE_1_0.txt |
| 5 | +//// |
| 6 | + |
| 7 | +[#decimal128_fast] |
| 8 | += Decimal128_fast |
| 9 | +:idprefix: decimal128_fast_ |
| 10 | + |
| 11 | +== Description |
| 12 | + |
| 13 | +`decimal128_fast` has the same ranges of values and representations as `decimal128_fast` but with greater performance. |
| 14 | +The performance changes by being non-IEEE 754 compliant so that the value does not have to be decoded from bits, but is instead directly represented internal to the type. |
| 15 | +As is often the case this trades space for time by having greater storage width requirements. |
| 16 | + |
| 17 | +- Storage width - 128 bits |
| 18 | +- Precision - 34 decimal digits (not bits like binary) |
| 19 | +- Max exponent - 6145 |
| 20 | +- Max Value - 9.99999...e6145 |
| 21 | +- Smallest normalized value - 1.0000...e-6142 |
| 22 | +- Smallest subnormal - 1e-6176 |
| 23 | + |
| 24 | +[source, c++] |
| 25 | +---- |
| 26 | +#include <boost/decimal/decimal128_fast.hpp> |
| 27 | +
|
| 28 | +namespace boost { |
| 29 | +namespace decimal { |
| 30 | +
|
| 31 | +// Paragraph numbers are from ISO/IEC DTR 24733 |
| 32 | +
|
| 33 | +// 3.2.4.1 construct/copy/destroy |
| 34 | +constexpr decimal128_fast() noexcept = default; |
| 35 | +
|
| 36 | +// 3.2.4.2 Conversion form floating-point type |
| 37 | +template <typename Float> |
| 38 | +explicit BOOST_DECIMAL_CXX20_CONSTEXPR decimal128_fast(Float val) noexcept; |
| 39 | +
|
| 40 | +// 3.2.4.3 Conversion from integral type |
| 41 | +template <typename Integer> |
| 42 | +explicit constexpr decimal128_fast(Integer val) noexcept; |
| 43 | +
|
| 44 | +template <typename Integral1, typename Integral2> |
| 45 | +constexpr decimal128_fast(Integral1 coeff, Integral2 exp, bool sign = false) noexcept; |
| 46 | +
|
| 47 | +template <typename Integral> |
| 48 | +constexpr decimal128_fast& operator=(const Integeral& RHS) noexcept; |
| 49 | +
|
| 50 | +// 3.2.4.4 Conversion to integral type |
| 51 | +explicit constexpr operator int() const noexcept; |
| 52 | +explicit constexpr operator unsigned() const noexcept; |
| 53 | +explicit constexpr operator long() const noexcept; |
| 54 | +explicit constexpr operator unsigned long() const noexcept; |
| 55 | +explicit constexpr operator long long() const noexcept; |
| 56 | +explicit constexpr operator unsigned long long() const noexcept; |
| 57 | +explicit constexpr operator std::int8_t() const noexcept; |
| 58 | +explicit constexpr operator std::uint8_t() const noexcept; |
| 59 | +explicit constexpr operator std::int16_t() const noexcept; |
| 60 | +explicit constexpr operator std::uint16_t() const noexcept; |
| 61 | +
|
| 62 | +// 3.2.4.5 increment and decrement operators: |
| 63 | +constexpr decimal128_fast& operator++(); |
| 64 | +constexpr decimal128_fast operator++(int); |
| 65 | +constexpr decimal128_fast& operator--(); |
| 66 | +constexpr decimal128_fast operator--(int); |
| 67 | +
|
| 68 | +// 3.2.4.6 compound assignment: |
| 69 | +constexpr decimal128_fast& operator+=(RHS rhs); |
| 70 | +constexpr decimal128_fast& operator-=(RHS rhs); |
| 71 | +constexpr decimal128_fast& operator*=(RHS rhs); |
| 72 | +constexpr decimal128_fast& operator/=(RHS rhs); |
| 73 | +
|
| 74 | +// 3.2.6 Conversion to floating-point type |
| 75 | +explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator float() const noexcept; |
| 76 | +explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator double() const noexcept; |
| 77 | +explicit BOOST_DECIMAL_CXX20_CONSTEXPR operator long double() const noexcept; |
| 78 | +
|
| 79 | +// The following are available assuming a C++23 compiler that provides the header <stdfloat> |
| 80 | +explicit constexpr operator std::float16_t() const noexcept; |
| 81 | +explicit constexpr operator std::float32_t() const noexcept; |
| 82 | +explicit constexpr operator std::float64_t() const noexcept; |
| 83 | +explicit constexpr operator std::bfloat16_t() const noexcept; |
| 84 | +
|
| 85 | +explicit constexpr operator decimal32() const noexcept; |
| 86 | +explicit constexpr operator decimal64() const noexcept; |
| 87 | +
|
| 88 | +} //namespace decimal |
| 89 | +} //namespace boost |
| 90 | +
|
| 91 | +---- |
0 commit comments