128#include <string_view>
132namespace nfx::datatypes
168 friend struct std::numeric_limits<
Decimal>;
223 inline explicit
Decimal(
float value ) noexcept;
239 explicit inline
Decimal( std::int32_t value ) noexcept;
245 explicit inline
Decimal( std::int64_t value ) noexcept;
251 explicit inline
Decimal( std::uint32_t value ) noexcept;
257 explicit inline
Decimal( std::uint64_t value ) noexcept;
265 explicit inline
Decimal( std::string_view str );
337 std::strong_ordering operator<=>( const
Decimal& other ) const noexcept;
345 bool operator==( const
Decimal& other ) const noexcept;
357 inline
bool operator==(
float val ) 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==(
double 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;
456 inline
bool operator==( std::int64_t val ) const noexcept;
463 inline
bool operator!=( std::int64_t val ) const noexcept;
470 inline
bool operator<( std::int64_t val ) const noexcept;
477 inline
bool operator<=( std::int64_t val ) const noexcept;
484 inline
bool operator>( std::int64_t val ) const noexcept;
491 inline
bool operator>=( std::int64_t val ) const noexcept;
498 inline
bool operator==( std::uint64_t val ) const noexcept;
505 inline
bool operator!=( std::uint64_t val ) const noexcept;
512 inline
bool operator<( std::uint64_t val ) const noexcept;
519 inline
bool operator<=( std::uint64_t val ) const noexcept;
526 inline
bool operator>( std::uint64_t val ) const noexcept;
533 inline
bool operator>=( std::uint64_t val ) const noexcept;
540 inline
bool operator==( std::int32_t val ) const noexcept;
547 inline
bool operator!=( std::int32_t val ) const noexcept;
554 inline
bool operator<( std::int32_t val ) const noexcept;
561 inline
bool operator<=( std::int32_t val ) const noexcept;
568 inline
bool operator>( std::int32_t val ) const noexcept;
575 inline
bool operator>=( std::int32_t val ) const noexcept;
587 bool operator==( const
Int128& val ) const noexcept;
594 inline
bool operator!=( const
Int128& val ) const noexcept;
601 bool operator<( const
Int128& val ) const noexcept;
608 inline
bool operator<=( const
Int128& val ) const noexcept;
615 inline
bool operator>( const
Int128& val ) const noexcept;
622 inline
bool operator>=( const
Int128& val ) const noexcept;
701 [[nodiscard]] std::uint8_t
scale() const noexcept;
708 [[nodiscard]] inline const std::uint32_t&
flags() const noexcept;
715 [[nodiscard]] inline std::uint32_t&
flags() noexcept;
722 [[nodiscard]] inline const std::array<std::uint32_t, 3>&
mantissa() const noexcept;
729 [[nodiscard]] inline std::array<std::uint32_t, 3>&
mantissa() noexcept;
849 [[nodiscard]] std::array<std::int32_t, 4>
toBits() const noexcept;
878 std::array<std::uint32_t, 3>
mantissa;
934 return value.floor();
950 return value.round( decimalsPlacesCount, mode );
962 return value.trunc();
966#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.