128#include <string_view>
132namespace nfx::datatypes
168 friend struct std::numeric_limits<
Decimal>;
239 inline explicit
Decimal( std::int32_t value ) noexcept;
245 inline explicit
Decimal( std::int64_t value ) noexcept;
251 inline explicit
Decimal( std::uint32_t value ) noexcept;
257 inline explicit
Decimal( std::uint64_t value ) noexcept;
265 inline explicit
Decimal( std::string_view str );
345 std::strong_ordering operator<=>( const
Decimal& other ) const noexcept;
353 bool operator==( const
Decimal& other ) const noexcept;
365 inline
bool operator==(
float val ) const noexcept;
373 inline
bool operator!=(
float val ) const noexcept;
381 inline
bool operator<(
float val ) const noexcept;
389 inline
bool operator<=(
float val ) const noexcept;
397 inline
bool operator>(
float val ) const noexcept;
405 inline
bool operator>=(
float val ) const noexcept;
413 inline
bool operator==(
double val ) const noexcept;
421 inline
bool operator!=(
double val ) const noexcept;
429 inline
bool operator<(
double val ) const noexcept;
437 inline
bool operator<=(
double val ) const noexcept;
445 inline
bool operator>(
double val ) const noexcept;
453 inline
bool operator>=(
double val ) const noexcept;
464 inline
bool operator==( std::int64_t val ) const noexcept;
471 inline
bool operator!=( std::int64_t val ) const noexcept;
478 inline
bool operator<( std::int64_t val ) const noexcept;
485 inline
bool operator<=( std::int64_t val ) const noexcept;
492 inline
bool operator>( std::int64_t val ) const noexcept;
499 inline
bool operator>=( std::int64_t val ) const noexcept;
506 inline
bool operator==( std::uint64_t val ) const noexcept;
513 inline
bool operator!=( std::uint64_t val ) const noexcept;
520 inline
bool operator<( std::uint64_t val ) const noexcept;
527 inline
bool operator<=( std::uint64_t val ) const noexcept;
534 inline
bool operator>( std::uint64_t val ) const noexcept;
541 inline
bool operator>=( std::uint64_t val ) const noexcept;
548 inline
bool operator==( std::int32_t val ) const noexcept;
555 inline
bool operator!=( std::int32_t val ) const noexcept;
562 inline
bool operator<( std::int32_t val ) const noexcept;
569 inline
bool operator<=( std::int32_t val ) const noexcept;
576 inline
bool operator>( std::int32_t val ) const noexcept;
583 inline
bool operator>=( std::int32_t val ) const noexcept;
595 bool operator==( const
Int128& val ) const noexcept;
602 inline
bool operator!=( const
Int128& val ) const noexcept;
609 bool operator<( const
Int128& val ) const noexcept;
616 inline
bool operator<=( const
Int128& val ) const noexcept;
623 inline
bool operator>( const
Int128& val ) const noexcept;
630 inline
bool operator>=( const
Int128& val ) const noexcept;
709 [[nodiscard]] std::uint8_t
scale() const noexcept;
716 [[nodiscard]] inline const std::uint32_t&
flags() const noexcept;
723 [[nodiscard]] inline std::uint32_t&
flags() noexcept;
730 [[nodiscard]] inline const std::array<std::uint32_t, 3>&
mantissa() const noexcept;
737 [[nodiscard]] inline std::array<std::uint32_t, 3>&
mantissa() noexcept;
857 [[nodiscard]] std::array<std::int32_t, 4>
toBits() const noexcept;
886 std::array<std::uint32_t, 3>
mantissa;
942 return value.floor();
958 return value.round( decimalsPlacesCount, mode );
970 return value.trunc();
974#include "nfx/detail/datatypes/Decimal.inl"
Cross-platform 128-bit integer arithmetic type.
Decimal floor(const Decimal &value) noexcept
Round down to nearest integer (free function).
Decimal round(const Decimal &value, std::int32_t decimalsPlacesCount=0, Decimal::RoundingMode mode=Decimal::RoundingMode::ToNearest) noexcept
Round decimal to specified precision (free function).
Decimal sqrt(const Decimal &value)
Compute square root using Newton-Raphson method (free function).
Decimal trunc(const Decimal &value) noexcept
Remove fractional part (free function).
Decimal ceil(const Decimal &value) noexcept
Round up to nearest integer (free function).
Decimal abs(const Decimal &value) noexcept
Get absolute value of decimal (free function).
Cross-platform high-precision decimal type.
Decimal ceil() const noexcept
Round up to nearest integer.
std::uint8_t scale() const noexcept
Get decimal scale (number of decimal places).
const std::array< std::uint32_t, 3 > & mantissa() const noexcept
Get mantissa array.
std::uint8_t decimalPlacesCount() const noexcept
Count actual decimal places (excluding trailing zeros).
const std::uint32_t & flags() const noexcept
Get flags value.
Decimal round(std::int32_t decimalsPlacesCount=0, RoundingMode mode=RoundingMode::ToNearest) const noexcept
Round decimal to specified precision using configurable rounding mode.
Decimal trunc() const noexcept
Remove fractional part.
Decimal abs() const noexcept
Get absolute value.
double toDouble() const noexcept
Convert to double (may lose precision).
static bool fromString(std::string_view str, Decimal &result) noexcept
Parse string to decimal with error handling.
std::string toString() const
Convert to string with exact precision.
constexpr Decimal() noexcept
Default constructor (zero value).
RoundingMode
Rounding modes for decimal arithmetic operations.
@ ToNearestTiesAway
Round to nearest, ties away from zero (standard rounding).
@ ToPositiveInfinity
Round towards +∞ (ceiling).
@ ToNearest
Round to nearest, ties to even (banker's rounding).
@ ToNegativeInfinity
Round towards -∞ (floor).
@ ToZero
Round towards zero (truncate).
Decimal sqrt() const
Compute square root using Newton-Raphson method.
Decimal floor() const noexcept
Round down to nearest integer.
std::array< std::int32_t, 4 > toBits() const noexcept
Get internal 32-bit representation.
Cross-platform 128-bit signed integer type.