nfx-datatypes 0.1.1
Cross-platform C++ library with high-precision Int128 and Decimal datatypes
Loading...
Searching...
No Matches
nfx::datatypes::Decimal Class Referencefinal

Cross-platform high-precision decimal type. More...

#include <nfx/datatypes/Decimal.h>

Public Types

enum class  RoundingMode : std::uint8_t {
  ToNearest = 0 ,
  ToNearestTiesAway ,
  ToZero ,
  ToPositiveInfinity ,
  ToNegativeInfinity
}
 Rounding modes for decimal arithmetic operations. More...

Public Member Functions

constexpr Decimal () noexcept
 Default constructor (zero value).
 Decimal (float value) noexcept
 Construct from single-precision floating-point value with IEEE 754-2008 input compatibility.
 Decimal (double value) noexcept
 Construct from double with IEEE 754-2008 input compatibility.
 Decimal (std::int32_t value) noexcept
 Construct from 32-bit integer.
 Decimal (std::int64_t value) noexcept
 Construct from 64-bit integer.
 Decimal (std::uint32_t value) noexcept
 Construct from 32-bit unsigned integer.
 Decimal (std::uint64_t value) noexcept
 Construct from 64-bit unsigned integer.
 Decimal (std::string_view str)
 Construct from string (exact parsing).
 Decimal (const Int128 &val)
 Construct from 128-bit integer with overflow detection.
 Decimal (const Decimal &other) noexcept=default
 Copy constructor.
 Decimal (Decimal &&other) noexcept=default
 Move constructor.
 ~Decimal ()=default
 Destructor.
Decimaloperator= (const Decimal &other) noexcept=default
 Copy assignment operator.
Decimaloperator= (Decimal &&other) noexcept=default
 Move assignment operator.
std::strong_ordering operator<=> (const Decimal &other) const noexcept
 Three-way comparison operator (C++20).
bool operator== (const Decimal &other) const noexcept
 Equality comparison operator.
bool operator== (float val) const noexcept
 Equality comparison with float.
bool operator!= (float val) const noexcept
 Inequality comparison with float.
bool operator< (float val) const noexcept
 Less than comparison with float.
bool operator<= (float val) const noexcept
 Less than or equal comparison with float.
bool operator> (float val) const noexcept
 Greater than comparison with float.
bool operator>= (float val) const noexcept
 Greater than or equal comparison with float.
bool operator== (double val) const noexcept
 Equality comparison with double.
bool operator!= (double val) const noexcept
 Inequality comparison with double.
bool operator< (double val) const noexcept
 Less than comparison with double.
bool operator<= (double val) const noexcept
 Less than or equal comparison with double.
bool operator> (double val) const noexcept
 Greater than comparison with double.
bool operator>= (double val) const noexcept
 Greater than or equal comparison with double.
bool operator== (std::int64_t val) const noexcept
 Equality comparison with signed 64-bit integer.
bool operator!= (std::int64_t val) const noexcept
 Inequality comparison with signed 64-bit integer.
bool operator< (std::int64_t val) const noexcept
 Less than comparison with signed 64-bit integer.
bool operator<= (std::int64_t val) const noexcept
 Less than or equal comparison with signed 64-bit integer.
bool operator> (std::int64_t val) const noexcept
 Greater than comparison with signed 64-bit integer.
bool operator>= (std::int64_t val) const noexcept
 Greater than or equal comparison with signed 64-bit integer.
bool operator== (std::uint64_t val) const noexcept
 Equality comparison with unsigned 64-bit integer.
bool operator!= (std::uint64_t val) const noexcept
 Inequality comparison with unsigned 64-bit integer.
bool operator< (std::uint64_t val) const noexcept
 Less than comparison with unsigned 64-bit integer.
bool operator<= (std::uint64_t val) const noexcept
 Less than or equal comparison with unsigned 64-bit integer.
bool operator> (std::uint64_t val) const noexcept
 Greater than comparison with unsigned 64-bit integer.
bool operator>= (std::uint64_t val) const noexcept
 Greater than or equal comparison with unsigned 64-bit integer.
bool operator== (std::int32_t val) const noexcept
 Equality comparison with signed 32-bit integer.
bool operator!= (std::int32_t val) const noexcept
 Inequality comparison with signed 32-bit integer.
bool operator< (std::int32_t val) const noexcept
 Less than comparison with signed 32-bit integer.
bool operator<= (std::int32_t val) const noexcept
 Less than or equal comparison with signed 32-bit integer.
bool operator> (std::int32_t val) const noexcept
 Greater than comparison with signed 32-bit integer.
bool operator>= (std::int32_t val) const noexcept
 Greater than or equal comparison with signed 32-bit integer.
bool operator== (const Int128 &val) const noexcept
 Equality comparison with Int128.
bool operator!= (const Int128 &val) const noexcept
 Inequality comparison with Int128.
bool operator< (const Int128 &val) const noexcept
 Less than comparison with Int128.
bool operator<= (const Int128 &val) const noexcept
 Less than or equal comparison with Int128.
bool operator> (const Int128 &val) const noexcept
 Greater than comparison with Int128.
bool operator>= (const Int128 &val) const noexcept
 Greater than or equal comparison with Int128.
Decimal operator+ (const Decimal &other)
 Addition operator.
Decimal operator- (const Decimal &other)
 Subtraction operator.
Decimal operator* (const Decimal &other) const
 Multiplication operator.
Decimal operator/ (const Decimal &other) const
 Division operator.
Decimaloperator+= (const Decimal &other)
 Addition assignment operator.
Decimaloperator-= (const Decimal &other)
 Subtraction assignment operator.
Decimaloperator*= (const Decimal &other)
 Multiplication assignment operator.
Decimaloperator/= (const Decimal &other)
 Division assignment operator.
Decimal operator- () const noexcept
 Unary minus operator (negation).
std::uint8_t scale () const noexcept
 Get decimal scale (number of decimal places).
const std::uint32_t & flags () const noexcept
 Get flags value.
std::uint32_t & flags () noexcept
 Get mutable flags value.
const std::array< std::uint32_t, 3 > & mantissa () const noexcept
 Get mantissa array.
std::array< std::uint32_t, 3 > & mantissa () noexcept
 Get mutable mantissa array.
Decimal abs () const noexcept
 Get absolute value.
Decimal ceil () const noexcept
 Round up to nearest integer.
Decimal floor () const noexcept
 Round down to nearest integer.
Decimal round (std::int32_t decimalsPlacesCount=0, RoundingMode mode=RoundingMode::ToNearest) const noexcept
 Round decimal to specified precision using configurable rounding mode.
Decimal sqrt () const
 Compute square root using Newton-Raphson method.
Decimal trunc () const noexcept
 Remove fractional part.
double toDouble () const noexcept
 Convert to double (may lose precision).
std::string toString () const
 Convert to string with exact precision.
std::array< std::int32_t, 4 > toBits () const noexcept
 Get internal 32-bit representation.
std::uint8_t decimalPlacesCount () const noexcept
 Count actual decimal places (excluding trailing zeros).

Static Public Member Functions

static bool fromString (std::string_view str, Decimal &result) noexcept
 Parse string to decimal with error handling.
static std::optional< DecimalfromString (std::string_view str) noexcept
 Parse string to decimal with optional return.

Friends

struct std::numeric_limits< Decimal >

Detailed Description

Cross-platform high-precision decimal type.

Implements exact decimal arithmetic with:

  • Range: ±79,228,162,514,264,337,593,543,950,335
  • 28 significant decimal digits maximum
  • 96-bit mantissa + 32-bit scale/sign = 128-bit total storage
  • Exact decimal arithmetic (no floating-point rounding errors)

Value Representation:

  • All values are of the form: mantissa / 10^scale
  • Mantissa: 96-bit unsigned integer (0 ≤ m < 2^96)
  • Sign: Stored separately in bit 31 of flags word
  • Scale: 0 to 28 inclusive (number of decimal places)

Financial Calculation Benefits:

  • Decimal fractions like 0.1 are represented exactly (no 0.099999... issues)
  • No round-off errors in monetary calculations
  • Predictable precision for financial applications

IEEE 754-2008 binary64 Input Compatibility:

  • Double constructor uses IEEE 754-2008 std::isnan and std::isinf functions
  • Respects IEEE 754 binary64 precision limits (~15-17 digits)
  • NaN and Infinity from double input are converted to zero
  • No internal NaN/Infinity states (division by zero throws std::overflow_error)
  • Use string constructor for values requiring exact decimal precision
Note
Note: This implements exact fixed-point decimal arithmetic, NOT IEEE 754 decimal128.

Definition at line 166 of file Decimal.h.

Member Enumeration Documentation

◆ RoundingMode

enum class nfx::datatypes::Decimal::RoundingMode : std::uint8_t
strong

Rounding modes for decimal arithmetic operations.

Defines how rounding should be performed when reducing decimal precision. Each mode follows industry-standard rounding semantics:

  • ToNearest (banker's rounding): Round to nearest value, ties round to even digit Examples: 2.5→2, 3.5→4, 4.5→4, 5.5→6 (minimizes cumulative rounding bias)
  • ToNearestTiesAway (standard rounding): Round to nearest value, ties away from zero Examples: 2.5→3, 3.5→4, -2.5→-3, -3.5→-4 (traditional "round half up" for positives)
  • ToZero (truncation): Round towards zero, discarding fractional part Examples: 2.9→2, -2.9→-2, 3.1→3, -3.1→-3
  • ToPositiveInfinity (ceiling): Round towards positive infinity Examples: 2.1→3, -2.9→-2, 3.0→3
  • ToNegativeInfinity (floor): Round towards negative infinity Examples: 2.9→2, -2.1→-3, 3.0→3
Enumerator
ToNearest 

Round to nearest, ties to even (banker's rounding).

ToNearestTiesAway 

Round to nearest, ties away from zero (standard rounding).

ToZero 

Round towards zero (truncate).

ToPositiveInfinity 

Round towards +∞ (ceiling).

ToNegativeInfinity 

Round towards -∞ (floor).

Definition at line 195 of file Decimal.h.

Constructor & Destructor Documentation

◆ Decimal() [1/10]

nfx::datatypes::Decimal::Decimal ( float value)
inlineexplicitnoexcept

Construct from single-precision floating-point value with IEEE 754-2008 input compatibility.

Parameters
valueFloat value to convert

Delegates to the double constructor for consistent behavior. Limited to IEEE 754 binary32 precision (~6-7 significant digits). Uses IEEE 754-2008 std::isnan and std::isinf for special value detection. NaN and Infinity values are converted to zero.

Note
For exact precision with fractional values, use string constructor instead. Float precision is inherently limited and may introduce rounding artifacts.
Here is the call graph for this function:

◆ Decimal() [2/10]

nfx::datatypes::Decimal::Decimal ( double value)
explicitnoexcept

Construct from double with IEEE 754-2008 input compatibility.

Parameters
valueDouble value to convert
Note
Limited to IEEE 754 binary64 precision (~15-17 significant digits). Uses IEEE 754-2008 std::isnan and std::isinf for special value detection. NaN and Infinity values are converted to zero. For exact precision, use string constructor instead.
Here is the call graph for this function:

◆ Decimal() [3/10]

nfx::datatypes::Decimal::Decimal ( std::int32_t value)
inlineexplicitnoexcept

Construct from 32-bit integer.

Parameters
valueInteger value to convert
Here is the call graph for this function:

◆ Decimal() [4/10]

nfx::datatypes::Decimal::Decimal ( std::int64_t value)
inlineexplicitnoexcept

Construct from 64-bit integer.

Parameters
valueInteger value to convert
Here is the call graph for this function:

◆ Decimal() [5/10]

nfx::datatypes::Decimal::Decimal ( std::uint32_t value)
inlineexplicitnoexcept

Construct from 32-bit unsigned integer.

Parameters
valueUnsigned integer value to convert
Here is the call graph for this function:

◆ Decimal() [6/10]

nfx::datatypes::Decimal::Decimal ( std::uint64_t value)
inlineexplicitnoexcept

Construct from 64-bit unsigned integer.

Parameters
valueUnsigned integer value to convert
Here is the call graph for this function:

◆ Decimal() [7/10]

nfx::datatypes::Decimal::Decimal ( std::string_view str)
inlineexplicit

Construct from string (exact parsing).

Parameters
strString representation (e.g., "123.456")
Exceptions
std::invalid_argumentif string is not a valid decimal
See also
fromString() for non-throwing parsing
Here is the call graph for this function:

◆ Decimal() [8/10]

nfx::datatypes::Decimal::Decimal ( const Int128 & val)
explicit

Construct from 128-bit integer with overflow detection.

Parameters
valInt128 value to convert
Exceptions
std::overflow_errorif Int128 value exceeds Decimal's 96-bit mantissa capacity

Converts Int128 to Decimal integer representation (scale = 0). Range Handling:

  • Int128 range: ±170,141,183,460,469,231,731,687,303,715,884,105,727/728 (2^127 - 1 / -2^127)
  • Decimal range: ±79,228,162,514,264,337,593,543,950,335 (2^96 - 1)

Overflow Behavior:

  • Values within Decimal's range are preserved exactly
  • Values exceeding Decimal's capacity throw std::overflow_error
  • Zero values are handled efficiently

Examples:

  • Int128(42) → Decimal("42")
  • Int128("-123") → Decimal("-123")
  • Int128("79228162514264337593543950335") → Decimal("79228162514264337593543950335") (max valid)
  • Int128("170141183460469231731687303715884105727") → throws std::overflow_error
  • Int128("-170141183460469231731687303715884105728") → throws std::overflow_error
Here is the call graph for this function:

◆ Decimal() [9/10]

nfx::datatypes::Decimal::Decimal ( const Decimal & other)
defaultnoexcept

Copy constructor.

Parameters
otherThe Decimal object to copy from
Here is the call graph for this function:

◆ Decimal() [10/10]

nfx::datatypes::Decimal::Decimal ( Decimal && other)
defaultnoexcept

Move constructor.

Parameters
otherThe Decimal object to move from
Here is the call graph for this function:

Member Function Documentation

◆ abs()

Decimal nfx::datatypes::Decimal::abs ( ) const
inlinenodiscardnoexcept

Get absolute value.

Returns
Absolute value of the decimal
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ceil()

Decimal nfx::datatypes::Decimal::ceil ( ) const
inlinenodiscardnoexcept

Round up to nearest integer.

Returns
Smallest integer greater than or equal to value
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decimalPlacesCount()

std::uint8_t nfx::datatypes::Decimal::decimalPlacesCount ( ) const
nodiscardnoexcept

Count actual decimal places (excluding trailing zeros).

Returns
Number of significant decimal places (0-28)

Examples:

  • Decimal("123.4500") returns 2 (trailing zeros ignored)
  • Decimal("123.000") returns 0 (integer value)
  • Decimal("0.001") returns 3
    Note
    This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flags() [1/2]

const std::uint32_t & nfx::datatypes::Decimal::flags ( ) const
inlinenodiscardnoexcept

Get flags value.

Returns
Reference to flags
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flags() [2/2]

std::uint32_t & nfx::datatypes::Decimal::flags ( )
inlinenodiscardnoexcept

Get mutable flags value.

Returns
Mutable reference to flags
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:

◆ floor()

Decimal nfx::datatypes::Decimal::floor ( ) const
inlinenodiscardnoexcept

Round down to nearest integer.

Returns
Largest integer less than or equal to value
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromString() [1/2]

std::optional< Decimal > nfx::datatypes::Decimal::fromString ( std::string_view str)
staticnodiscardnoexcept

Parse string to decimal with optional return.

Parameters
strString to parse (e.g., "123.45", "-0.001", "42")
Returns
std::optional<Decimal> containing parsed value if successful, std::nullopt if parsing failed

This is a convenience wrapper around the two-parameter fromString method. Supports the same input formats:

  • Integers: "123", "-456"
  • Decimals: "123.45", "-0.001"
  • Scientific notation: "1.23e5", "-4.56E-3"
  • Leading/trailing whitespace is trimmed
  • Positive signs are optional: "+123.45" → 123.45
  • Maximum precision: 28 significant decimal digits
    Note
    This function is marked [[nodiscard]] - the return value should not be ignored
    For error details, use the two-parameter overload with explicit error handling
    Range: ±79,228,162,514,264,337,593,543,950,335 with up to 28 decimal places
Here is the call graph for this function:

◆ fromString() [2/2]

bool nfx::datatypes::Decimal::fromString ( std::string_view str,
Decimal & result )
staticnodiscardnoexcept

Parse string to decimal with error handling.

Parameters
strString to parse (e.g., "123.45", "-0.001", "42")
resultOutput decimal value
Returns
true if parsing succeeded, false otherwise

Parses string representations of decimal numbers with comprehensive format support. Supported input formats:

  • Integers: "123", "-456"
  • Decimals: "123.45", "-0.001"
  • Scientific notation: "1.23e5", "-4.56E-3"
  • Leading/trailing whitespace is trimmed
  • Positive signs are optional: "+123.45" → 123.45
  • Maximum precision: 28 significant decimal digits
    Note
    This function is marked [[nodiscard]] - the return value should not be ignored
    Range: ±79,228,162,514,264,337,593,543,950,335 with up to 28 decimal places
    For convenience wrapper with std::optional return, use the single-parameter overload
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mantissa() [1/2]

const std::array< std::uint32_t, 3 > & nfx::datatypes::Decimal::mantissa ( ) const
inlinenodiscardnoexcept

Get mantissa array.

Returns
Reference to mantissa array
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mantissa() [2/2]

std::array< std::uint32_t, 3 > & nfx::datatypes::Decimal::mantissa ( )
inlinenodiscardnoexcept

Get mutable mantissa array.

Returns
Mutable reference to mantissa array
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:

◆ operator!=() [1/6]

bool nfx::datatypes::Decimal::operator!= ( const Int128 & val) const
inlinenoexcept

Inequality comparison with Int128.

Parameters
valRight operand
Returns
true if values are not equal

◆ operator!=() [2/6]

bool nfx::datatypes::Decimal::operator!= ( double val) const
inlinenoexcept

Inequality comparison with double.

Parameters
valRight operand
Returns
true if values are not equal (subject to floating-point precision)
Note
Comparison may have precision limitations due to double's ~15-17 digit precision

◆ operator!=() [3/6]

bool nfx::datatypes::Decimal::operator!= ( float val) const
inlinenoexcept

Inequality comparison with float.

Parameters
valRight operand
Returns
true if values are not equal (subject to floating-point precision)
Note
Comparison may have precision limitations due to float's ~6-7 digit precision

◆ operator!=() [4/6]

bool nfx::datatypes::Decimal::operator!= ( std::int32_t val) const
inlinenoexcept

Inequality comparison with signed 32-bit integer.

Parameters
valRight operand
Returns
true if values are not equal

◆ operator!=() [5/6]

bool nfx::datatypes::Decimal::operator!= ( std::int64_t val) const
inlinenoexcept

Inequality comparison with signed 64-bit integer.

Parameters
valRight operand
Returns
true if values are not equal

◆ operator!=() [6/6]

bool nfx::datatypes::Decimal::operator!= ( std::uint64_t val) const
inlinenoexcept

Inequality comparison with unsigned 64-bit integer.

Parameters
valRight operand
Returns
true if values are not equal

◆ operator*()

Decimal nfx::datatypes::Decimal::operator* ( const Decimal & other) const

Multiplication operator.

Parameters
otherThe Decimal value to multiply by
Returns
Result of multiplication
Here is the call graph for this function:

◆ operator*=()

Decimal & nfx::datatypes::Decimal::operator*= ( const Decimal & other)
inline

Multiplication assignment operator.

Parameters
otherThe Decimal value to multiply by
Returns
Reference to this Decimal after multiplication
Here is the call graph for this function:

◆ operator+()

Decimal nfx::datatypes::Decimal::operator+ ( const Decimal & other)

Addition operator.

Parameters
otherThe Decimal value to add
Returns
Result of addition
Here is the call graph for this function:

◆ operator+=()

Decimal & nfx::datatypes::Decimal::operator+= ( const Decimal & other)
inline

Addition assignment operator.

Parameters
otherThe Decimal value to add
Returns
Reference to this Decimal after addition
Here is the call graph for this function:

◆ operator-() [1/2]

Decimal nfx::datatypes::Decimal::operator- ( ) const
inlinenoexcept

Unary minus operator (negation).

Returns
Negated decimal value
Here is the call graph for this function:

◆ operator-() [2/2]

Decimal nfx::datatypes::Decimal::operator- ( const Decimal & other)
inline

Subtraction operator.

Parameters
otherThe Decimal value to subtract
Returns
Result of subtraction
Here is the call graph for this function:

◆ operator-=()

Decimal & nfx::datatypes::Decimal::operator-= ( const Decimal & other)
inline

Subtraction assignment operator.

Parameters
otherThe Decimal value to subtract
Returns
Reference to this Decimal after subtraction
Here is the call graph for this function:

◆ operator/()

Decimal nfx::datatypes::Decimal::operator/ ( const Decimal & other) const

Division operator.

Parameters
otherDivisor
Returns
Result of division
Exceptions
std::overflow_errorif divisor is zero (no NaN/Infinity representation)
Here is the call graph for this function:

◆ operator/=()

Decimal & nfx::datatypes::Decimal::operator/= ( const Decimal & other)
inline

Division assignment operator.

Parameters
otherDivisor
Returns
Reference to this after division
Exceptions
std::overflow_errorif divisor is zero (no NaN/Infinity representation)
Here is the call graph for this function:

◆ operator<() [1/6]

bool nfx::datatypes::Decimal::operator< ( const Int128 & val) const
noexcept

Less than comparison with Int128.

Parameters
valRight operand
Returns
true if this is less than val

◆ operator<() [2/6]

bool nfx::datatypes::Decimal::operator< ( double val) const
inlinenoexcept

Less than comparison with double.

Parameters
valRight operand
Returns
true if this is less than val (subject to floating-point precision)
Note
Comparison may have precision limitations due to double's ~15-17 digit precision

◆ operator<() [3/6]

bool nfx::datatypes::Decimal::operator< ( float val) const
inlinenoexcept

Less than comparison with float.

Parameters
valRight operand
Returns
true if this is less than val (subject to floating-point precision)
Note
Comparison may have precision limitations due to float's ~6-7 digit precision

◆ operator<() [4/6]

bool nfx::datatypes::Decimal::operator< ( std::int32_t val) const
inlinenoexcept

Less than comparison with signed 32-bit integer.

Parameters
valRight operand
Returns
true if this is less than val

◆ operator<() [5/6]

bool nfx::datatypes::Decimal::operator< ( std::int64_t val) const
inlinenoexcept

Less than comparison with signed 64-bit integer.

Parameters
valRight operand
Returns
true if this is less than val

◆ operator<() [6/6]

bool nfx::datatypes::Decimal::operator< ( std::uint64_t val) const
inlinenoexcept

Less than comparison with unsigned 64-bit integer.

Parameters
valRight operand
Returns
true if this is less than val

◆ operator<=() [1/6]

bool nfx::datatypes::Decimal::operator<= ( const Int128 & val) const
inlinenoexcept

Less than or equal comparison with Int128.

Parameters
valRight operand
Returns
true if this is less than or equal to val

◆ operator<=() [2/6]

bool nfx::datatypes::Decimal::operator<= ( double val) const
inlinenoexcept

Less than or equal comparison with double.

Parameters
valRight operand
Returns
true if this is less than or equal to val (subject to floating-point precision)
Note
Comparison may have precision limitations due to double's ~15-17 digit precision

◆ operator<=() [3/6]

bool nfx::datatypes::Decimal::operator<= ( float val) const
inlinenoexcept

Less than or equal comparison with float.

Parameters
valRight operand
Returns
true if this is less than or equal to val (subject to floating-point precision)
Note
Comparison may have precision limitations due to float's ~6-7 digit precision

◆ operator<=() [4/6]

bool nfx::datatypes::Decimal::operator<= ( std::int32_t val) const
inlinenoexcept

Less than or equal comparison with signed 32-bit integer.

Parameters
valRight operand
Returns
true if this is less than or equal to val

◆ operator<=() [5/6]

bool nfx::datatypes::Decimal::operator<= ( std::int64_t val) const
inlinenoexcept

Less than or equal comparison with signed 64-bit integer.

Parameters
valRight operand
Returns
true if this is less than or equal to val

◆ operator<=() [6/6]

bool nfx::datatypes::Decimal::operator<= ( std::uint64_t val) const
inlinenoexcept

Less than or equal comparison with unsigned 64-bit integer.

Parameters
valRight operand
Returns
true if this is less than or equal to val

◆ operator<=>()

std::strong_ordering nfx::datatypes::Decimal::operator<=> ( const Decimal & other) const
noexcept

Three-way comparison operator (C++20).

Parameters
otherThe Decimal value to compare with
Returns
std::strong_ordering indicating relative order (less, equal, or greater)
Note
Compiler auto-generates operator!=, <, <=, >, >= from this operator
Here is the call graph for this function:

◆ operator=() [1/2]

Decimal & nfx::datatypes::Decimal::operator= ( const Decimal & other)
defaultnoexcept

Copy assignment operator.

Parameters
otherThe Decimal object to copy from
Returns
Reference to this Decimal object after assignment
Here is the call graph for this function:

◆ operator=() [2/2]

Decimal & nfx::datatypes::Decimal::operator= ( Decimal && other)
defaultnoexcept

Move assignment operator.

Parameters
otherThe Decimal object to move from
Returns
Reference to this Decimal object after assignment
Here is the call graph for this function:

◆ operator==() [1/7]

bool nfx::datatypes::Decimal::operator== ( const Decimal & other) const
noexcept

Equality comparison operator.

Parameters
otherThe Decimal value to compare with
Returns
true if values are equal, false otherwise
Note
Required alongside operator<=> for complete C++20 comparison support
Here is the call graph for this function:

◆ operator==() [2/7]

bool nfx::datatypes::Decimal::operator== ( const Int128 & val) const
noexcept

Equality comparison with Int128.

Parameters
valRight operand
Returns
true if values are equal
Note
For equality, the Decimal must have no fractional part and represent the same integer value

◆ operator==() [3/7]

bool nfx::datatypes::Decimal::operator== ( double val) const
inlinenoexcept

Equality comparison with double.

Parameters
valRight operand
Returns
true if values are equal (subject to floating-point precision)
Note
Comparison may have precision limitations due to double's ~15-17 digit precision

◆ operator==() [4/7]

bool nfx::datatypes::Decimal::operator== ( float val) const
inlinenoexcept

Equality comparison with float.

Parameters
valRight operand
Returns
true if values are equal (subject to floating-point precision)
Note
Comparison may have precision limitations due to float's ~6-7 digit precision

◆ operator==() [5/7]

bool nfx::datatypes::Decimal::operator== ( std::int32_t val) const
inlinenoexcept

Equality comparison with signed 32-bit integer.

Parameters
valRight operand
Returns
true if values are equal

◆ operator==() [6/7]

bool nfx::datatypes::Decimal::operator== ( std::int64_t val) const
inlinenoexcept

Equality comparison with signed 64-bit integer.

Parameters
valRight operand
Returns
true if values are equal

◆ operator==() [7/7]

bool nfx::datatypes::Decimal::operator== ( std::uint64_t val) const
inlinenoexcept

Equality comparison with unsigned 64-bit integer.

Parameters
valRight operand
Returns
true if values are equal

◆ operator>() [1/6]

bool nfx::datatypes::Decimal::operator> ( const Int128 & val) const
inlinenoexcept

Greater than comparison with Int128.

Parameters
valRight operand
Returns
true if this is greater than val

◆ operator>() [2/6]

bool nfx::datatypes::Decimal::operator> ( double val) const
inlinenoexcept

Greater than comparison with double.

Parameters
valRight operand
Returns
true if this is greater than val (subject to floating-point precision)
Note
Comparison may have precision limitations due to double's ~15-17 digit precision

◆ operator>() [3/6]

bool nfx::datatypes::Decimal::operator> ( float val) const
inlinenoexcept

Greater than comparison with float.

Parameters
valRight operand
Returns
true if this is greater than val (subject to floating-point precision)
Note
Comparison may have precision limitations due to float's ~6-7 digit precision

◆ operator>() [4/6]

bool nfx::datatypes::Decimal::operator> ( std::int32_t val) const
inlinenoexcept

Greater than comparison with signed 32-bit integer.

Parameters
valRight operand
Returns
true if this is greater than val

◆ operator>() [5/6]

bool nfx::datatypes::Decimal::operator> ( std::int64_t val) const
inlinenoexcept

Greater than comparison with signed 64-bit integer.

Parameters
valRight operand
Returns
true if this is greater than val

◆ operator>() [6/6]

bool nfx::datatypes::Decimal::operator> ( std::uint64_t val) const
inlinenoexcept

Greater than comparison with unsigned 64-bit integer.

Parameters
valRight operand
Returns
true if this is greater than val

◆ operator>=() [1/6]

bool nfx::datatypes::Decimal::operator>= ( const Int128 & val) const
inlinenoexcept

Greater than or equal comparison with Int128.

Parameters
valRight operand
Returns
true if this is greater than or equal to val

◆ operator>=() [2/6]

bool nfx::datatypes::Decimal::operator>= ( double val) const
inlinenoexcept

Greater than or equal comparison with double.

Parameters
valRight operand
Returns
true if this is greater than or equal to val (subject to floating-point precision)
Note
Comparison may have precision limitations due to double's ~15-17 digit precision

◆ operator>=() [3/6]

bool nfx::datatypes::Decimal::operator>= ( float val) const
inlinenoexcept

Greater than or equal comparison with float.

Parameters
valRight operand
Returns
true if this is greater than or equal to val (subject to floating-point precision)
Note
Comparison may have precision limitations due to float's ~6-7 digit precision

◆ operator>=() [4/6]

bool nfx::datatypes::Decimal::operator>= ( std::int32_t val) const
inlinenoexcept

Greater than or equal comparison with signed 32-bit integer.

Parameters
valRight operand
Returns
true if this is greater than or equal to val

◆ operator>=() [5/6]

bool nfx::datatypes::Decimal::operator>= ( std::int64_t val) const
inlinenoexcept

Greater than or equal comparison with signed 64-bit integer.

Parameters
valRight operand
Returns
true if this is greater than or equal to val

◆ operator>=() [6/6]

bool nfx::datatypes::Decimal::operator>= ( std::uint64_t val) const
inlinenoexcept

Greater than or equal comparison with unsigned 64-bit integer.

Parameters
valRight operand
Returns
true if this is greater than or equal to val

◆ round()

Decimal nfx::datatypes::Decimal::round ( std::int32_t decimalsPlacesCount = 0,
RoundingMode mode = RoundingMode::ToNearest ) const
nodiscardnoexcept

Round decimal to specified precision using configurable rounding mode.

Parameters
decimalsPlacesCountNumber of decimal places to round to (default: 0 for integer rounding)
modeRounding mode to apply (default: RoundingMode::ToNearest for banker's rounding)
Returns
Decimal value rounded to the specified precision
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ scale()

std::uint8_t nfx::datatypes::Decimal::scale ( ) const
nodiscardnoexcept

Get decimal scale (number of decimal places).

Returns
Scale value (0-28)
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sqrt()

Decimal nfx::datatypes::Decimal::sqrt ( ) const
nodiscard

Compute square root using Newton-Raphson method.

Returns
Square root with full decimal precision (up to 28 digits)
Exceptions
std::domain_errorif called on negative value

Uses iterative Newton-Raphson algorithm: x_{n+1} = (x_n + value/x_n) / 2 Converges quadratically for positive values. Returns exact result for perfect squares within precision limits.

Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toBits()

std::array< std::int32_t, 4 > nfx::datatypes::Decimal::toBits ( ) const
nodiscardnoexcept

Get internal 32-bit representation.

Returns
Array of 4 32-bit integers representing the decimal
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toDouble()

double nfx::datatypes::Decimal::toDouble ( ) const
nodiscardnoexcept

Convert to double (may lose precision).

Returns
Double representation
Note
Conversion may lose precision beyond ~15-17 significant digits
For exact precision, use toString() method instead
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

std::string nfx::datatypes::Decimal::toString ( ) const
nodiscard

Convert to string with exact precision.

Returns
String representation
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ trunc()

Decimal nfx::datatypes::Decimal::trunc ( ) const
inlinenodiscardnoexcept

Remove fractional part.

Returns
Decimal with fractional part removed
Note
This function is marked [[nodiscard]] - the return value should not be ignored
Here is the call graph for this function:
Here is the caller graph for this function:

◆ std::numeric_limits< Decimal >

friend struct std::numeric_limits< Decimal >
friend

Definition at line 960 of file Decimal.h.


The documentation for this class was generated from the following file: