Represents 128-bit fixed-point decimal numbers. The max decimal precision that can be safely represented is 38 significant digits.
More...
|
|
constexpr | Decimal () noexcept=default |
| | Default constructor initializes to zero.
|
| |
|
constexpr | Decimal (int128_t value) noexcept |
| | Create a Decimal from a 128-bit integer.
|
| |
template<typename T >
requires (std::is_integral_v<T> && (sizeof(T) <= sizeof(uint64_t))) |
| constexpr | Decimal (T value) noexcept |
| | Create a Decimal from any integer not wider than 64 bits.
|
| |
| | Decimal (std::string_view str) |
| | Parse a Decimal from a string representation.
|
| |
|
constexpr | Decimal (int64_t high, uint64_t low) noexcept |
| | Create a Decimal from two 64-bit integers.
|
| |
|
Decimal & | Negate () |
| | Negate the current Decimal value (in place)
|
| |
|
Decimal & | Abs () |
| | Absolute value of the current Decimal value (in place)
|
| |
|
Decimal & | operator+= (const Decimal &other) |
| | Add a number to this one. The result is truncated to 128 bits.
|
| |
|
Decimal & | operator-= (const Decimal &other) |
| | Subtract a number from this one. The result is truncated to 128 bits.
|
| |
|
Decimal & | operator*= (const Decimal &other) |
| | Multiply this number by another. The result is truncated to 128 bits.
|
| |
| Result< std::pair< Decimal, Decimal > > | Divide (const Decimal &divisor) const |
| | Divide this number by another.
|
| |
|
Decimal & | operator/= (const Decimal &other) |
| | In place division.
|
| |
|
Decimal & | operator|= (const Decimal &other) |
| | Bitwise OR operation.
|
| |
|
Decimal & | operator&= (const Decimal &other) |
| | Bitwise AND operation.
|
| |
|
Decimal & | operator<<= (uint32_t shift) |
| | Shift left by the given number of bits (in place).
|
| |
|
Decimal | operator<< (uint32_t shift) const |
| | Shift left by the given number of bits.
|
| |
|
Decimal & | operator>>= (uint32_t shift) |
| | Shift right by the given number of bits (in place).
|
| |
|
Decimal | operator>> (uint32_t shift) const |
| | Shift right by the given number of bits.
|
| |
|
constexpr int128_t | value () const |
| | Get the underlying 128-bit integer representation of the number.
|
| |
|
constexpr int64_t | high () const |
| | Get the high bits of the two's complement representation of the number.
|
| |
|
constexpr uint64_t | low () const |
| | Get the low bits of the two's complement representation of the number.
|
| |
| Result< std::string > | ToString (int32_t scale) const |
| | Convert the Decimal value to a base 10 decimal string with the given scale.
|
| |
|
std::string | ToIntegerString () const |
| | Convert the Decimal value to an integer string.
|
| |
| std::string | ToString () const override |
| | Returns an integer string representation of the decimal value.
|
| |
| std::vector< uint8_t > | ToBigEndian () const |
| | Convert Decimal's unscaled value to two’s-complement big-endian binary, using the minimum number of bytes for the value.
|
| |
|
Result< Decimal > | Rescale (int32_t orig_scale, int32_t new_scale) const |
| | Convert Decimal from one scale to another.
|
| |
| bool | FitsInPrecision (int32_t precision) const |
| | Whether this number fits in the given precision.
|
| |
|
std::strong_ordering | operator<=> (const Decimal &other) const |
| | Spaceship operator for three-way comparison.
|
| |
|
const uint8_t * | native_endian_bytes () const |
| |
|
std::array< uint8_t, kByteWidth > | ToBytes () const |
| | Returns the raw bytes of the value in native-endian byte order.
|
| |
|
int64_t | Sign () const |
| | Returns 1 if positive or zero, -1 if strictly negative.
|
| |
|
bool | IsNegative () const |
| | Check if the Decimal value is negative.
|
| |
|
| operator bool () const |
| |
|
|
static Decimal | Abs (const Decimal &value) |
| | Absolute value of the current Decimal value.
|
| |
| static Result< Decimal > | FromString (std::string_view str, int32_t *precision=nullptr, int32_t *scale=nullptr) |
| | Convert the decimal string to a Decimal value, optionally including precision and scale if they are provided not null.
|
| |
| static Result< Decimal > | FromBigEndian (const uint8_t *data, int32_t length) |
| | Convert from a big-endian byte representation. The length must be between 1 and 16.
|
| |
|
static std::partial_ordering | Compare (const Decimal &lhs, const Decimal &rhs, int32_t lhs_scale, int32_t rhs_scale) |
| | Compare two Decimals with different scales.
|
| |
Represents 128-bit fixed-point decimal numbers. The max decimal precision that can be safely represented is 38 significant digits.