Pecunia 0.9.0-alpha.22
Library using the ISO-4217 currency standard & a fixed monetary unit size
Loading...
Searching...
No Matches
pecunia::FloatingPoint Class Reference

Represents a safe type for working with floating-point operations. More...

#include <FloatingPoint.hpp>

Collaboration diagram for pecunia::FloatingPoint:

Public Member Functions

 FloatingPoint ()
 Fully initialises the value to zero.
 
 FloatingPoint (const FloatingPointBase &value)
 Fully initialises the value.
 
 FloatingPoint (const std::int32_t &value)
 Fully initialises the value.
 
 FloatingPoint (const std::int64_t &value)
 Fully initialises the value.
 
FloatingPoint absoluteValue () const
 Performs the mathematical absolute value operation.
 
FloatingPoint ceiling () const
 Performs the mathematical ceiling operation.
 
RealNumber decompose (const std::uint8_t digits=defaultRoundingDigits) const
 Breaks a floating-point number into its whole and fractional components.
 
FloatingPoint floor () const
 Performs the mathematical floor operation.
 
bool isEqual (const FloatingPoint &other, const std::uint8_t digits=defaultRoundingDigits) const
 Determines if the supplied number is equal to within a specific number of digits.
 
FloatingPoint modulo (const FloatingPoint &divisor) const
 Calculates the modulo operation, i.e. division remainder.
 
FloatingPoint operator* (const FloatingPoint &other) const
 Calculates the multiplication operation.
 
FloatingPointoperator*= (const FloatingPoint &other)
 Calculates the multiplication and assignment operation.
 
FloatingPoint operator+ (const FloatingPoint &other) const
 Calculates the addition operation.
 
FloatingPointoperator+= (const FloatingPoint &other)
 Calculates the addition and assignment operation.
 
FloatingPoint operator- () const
 Negation operator.
 
FloatingPoint operator- (const FloatingPoint &other) const
 Calculates the subtraction operation.
 
FloatingPointoperator-= (const FloatingPoint &other)
 Calculates the subtraction and assignment operation.
 
FloatingPoint operator/ (const FloatingPoint &divisor) const
 Calculates the division operation.
 
FloatingPointoperator/= (const FloatingPoint &divisor)
 Calculates the division and assignment operation.
 
bool operator< (const FloatingPoint &other) const noexcept
 Relationship operator checking the less-than status.
 
bool operator< (const FloatingPointBase &other) const noexcept
 Relationship operator checking the less-than status.
 
bool operator<= (const FloatingPoint &other) const =delete
 
bool operator<= (const FloatingPointBase &other) const =delete
 
bool operator== (const FloatingPoint &other) const =delete
 
bool operator== (const FloatingPointBase &other) const =delete
 
bool operator> (const FloatingPoint &other) const noexcept
 Relationship operator checking the greater-than status.
 
bool operator> (const FloatingPointBase &other) const noexcept
 Relationship operator checking the greater-than status.
 
bool operator>= (const FloatingPoint &other) const =delete
 
bool operator>= (const FloatingPointBase &other) const =delete
 
FloatingPoint power (const FloatingPoint &exponent) const
 Performs the exponentiation operation.
 
FloatingPoint power (const std::int64_t &exponent) const
 Performs the exponentiation operation.
 
FloatingPoint reciprocal () const
 Calculates the reciprocal of the current instance's value.
 
FloatingPoint squareRoot () const
 Calculates the square root of the stored value.
 
std::string toString () const
 Converts the float-point value into a string.
 
const FloatingPointBase & underlying () const noexcept
 The unsafe type represented by the floating-point value.
 

Detailed Description

Represents a safe type for working with floating-point operations.

Constructor & Destructor Documentation

◆ FloatingPoint() [1/4]

pecunia::FloatingPoint::FloatingPoint ( )

Fully initialises the value to zero.

◆ FloatingPoint() [2/4]

pecunia::FloatingPoint::FloatingPoint ( const FloatingPointBase & value)

Fully initialises the value.

Parameters
valueThe value to set the floating-point to.

◆ FloatingPoint() [3/4]

pecunia::FloatingPoint::FloatingPoint ( const std::int32_t & value)

Fully initialises the value.

Parameters
valueThe value to set the floating-point to.

◆ FloatingPoint() [4/4]

pecunia::FloatingPoint::FloatingPoint ( const std::int64_t & value)

Fully initialises the value.

Parameters
valueThe value to set the floating-point to.

Member Function Documentation

◆ absoluteValue()

FloatingPoint pecunia::FloatingPoint::absoluteValue ( ) const
nodiscard

Performs the mathematical absolute value operation.

Returns
The result of the absolute value operation on the current value.

◆ ceiling()

FloatingPoint pecunia::FloatingPoint::ceiling ( ) const
nodiscard

Performs the mathematical ceiling operation.

Returns
The result of the ceiling operation on the current value.

◆ decompose()

RealNumber pecunia::FloatingPoint::decompose ( const std::uint8_t digits = defaultRoundingDigits) const
nodiscard

Breaks a floating-point number into its whole and fractional components.

Parameters
digitsThe number of digits of precision to have in the fractional portion.
Returns
The split floating-point number.

◆ floor()

FloatingPoint pecunia::FloatingPoint::floor ( ) const
nodiscard

Performs the mathematical floor operation.

Returns
The result of the floor operation on the current value.

◆ isEqual()

bool pecunia::FloatingPoint::isEqual ( const FloatingPoint & other,
const std::uint8_t digits = defaultRoundingDigits ) const
nodiscard

Determines if the supplied number is equal to within a specific number of digits.

Parameters
otherThe other floating-point value to compare the current instance to.
digitsThe number of digits of precision to compare the two numbers to.
Returns
True when all numbers before the precision digit is equal, false else-wise. Any number at or beyond the precision digit is ignored.

◆ modulo()

FloatingPoint pecunia::FloatingPoint::modulo ( const FloatingPoint & divisor) const
nodiscard

Calculates the modulo operation, i.e. division remainder.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
DomainErrorWhen the result of the operation would result in a division by zero.
Parameters
divisorThe value to perform the modulo of the current stored value (dividend) with.
Returns
The result of the operation.

◆ operator*()

FloatingPoint pecunia::FloatingPoint::operator* ( const FloatingPoint & other) const
nodiscard

Calculates the multiplication operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
Parameters
otherThe value to multiply the current stored value with.
Returns
The result of the operation.

◆ operator*=()

FloatingPoint & pecunia::FloatingPoint::operator*= ( const FloatingPoint & other)

Calculates the multiplication and assignment operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
Parameters
otherThe value to multiply the current stored value with.
Postcondition
The result of the operation is stored in the current object.
Returns
The current object.

◆ operator+()

FloatingPoint pecunia::FloatingPoint::operator+ ( const FloatingPoint & other) const
nodiscard

Calculates the addition operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
Parameters
otherThe value to add to the current stored value.
Returns
The result of the operation.

◆ operator+=()

FloatingPoint & pecunia::FloatingPoint::operator+= ( const FloatingPoint & other)

Calculates the addition and assignment operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
Parameters
otherThe value to add to the current stored value.
Postcondition
The result of the operation is stored in the current object.
Returns
The current object.

◆ operator-() [1/2]

FloatingPoint pecunia::FloatingPoint::operator- ( ) const
nodiscard

Negation operator.

Returns
Gives the negation result of the current value.

◆ operator-() [2/2]

FloatingPoint pecunia::FloatingPoint::operator- ( const FloatingPoint & other) const
nodiscard

Calculates the subtraction operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
Parameters
otherThe value to subtract from the current stored value.
Returns
The result of the operation.

◆ operator-=()

FloatingPoint & pecunia::FloatingPoint::operator-= ( const FloatingPoint & other)

Calculates the subtraction and assignment operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
Parameters
otherThe value to subtract to the current stored value.
Postcondition
The result of the operation is stored in the current object.
Returns
The current object.

◆ operator/()

FloatingPoint pecunia::FloatingPoint::operator/ ( const FloatingPoint & divisor) const
nodiscard

Calculates the division operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
DomainErrorWhen the result of the operation would result in a division by zero.
Parameters
divisorThe value to divide the current stored value (dividend) with.
Returns
The result of the operation.

◆ operator/=()

FloatingPoint & pecunia::FloatingPoint::operator/= ( const FloatingPoint & divisor)

Calculates the division and assignment operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
DomainErrorWhen the result of the operation would result in a division by zero.
Parameters
divisorThe value to divide the current stored value (dividend) with.
Postcondition
The result of the operation is stored in the current object.
Returns
The current object.

◆ operator<() [1/2]

bool pecunia::FloatingPoint::operator< ( const FloatingPoint & other) const
nodiscardnoexcept

Relationship operator checking the less-than status.

Parameters
otherThe value to check the relationship with the current value.
Returns
Gives true when the current value is less-than the supplied value.

◆ operator<() [2/2]

bool pecunia::FloatingPoint::operator< ( const FloatingPointBase & other) const
nodiscardnoexcept

Relationship operator checking the less-than status.

Parameters
otherThe value to check the relationship with the current value.
Returns
Gives true when the current value is less-than the supplied value.

◆ operator<=() [1/2]

bool pecunia::FloatingPoint::operator<= ( const FloatingPoint & other) const
delete

◆ operator<=() [2/2]

bool pecunia::FloatingPoint::operator<= ( const FloatingPointBase & other) const
delete

◆ operator==() [1/2]

bool pecunia::FloatingPoint::operator== ( const FloatingPoint & other) const
delete

◆ operator==() [2/2]

bool pecunia::FloatingPoint::operator== ( const FloatingPointBase & other) const
delete

◆ operator>() [1/2]

bool pecunia::FloatingPoint::operator> ( const FloatingPoint & other) const
nodiscardnoexcept

Relationship operator checking the greater-than status.

Parameters
otherThe value to check the relationship with the current value.
Returns
Gives true when the current value is greater-than the supplied value.

◆ operator>() [2/2]

bool pecunia::FloatingPoint::operator> ( const FloatingPointBase & other) const
nodiscardnoexcept

Relationship operator checking the greater-than status.

Parameters
otherThe value to check the relationship with the current value.
Returns
Gives true when the current value is greater-than the supplied value.

◆ operator>=() [1/2]

bool pecunia::FloatingPoint::operator>= ( const FloatingPoint & other) const
delete

◆ operator>=() [2/2]

bool pecunia::FloatingPoint::operator>= ( const FloatingPointBase & other) const
delete

◆ power() [1/2]

FloatingPoint pecunia::FloatingPoint::power ( const FloatingPoint & exponent) const
nodiscard

Performs the exponentiation operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
DomainErrorWhen the result of the operation would result in a division by zero.
Parameters
exponentThe power to raise the base value to.
Returns
The result of raising the current value, the base, to the power of the supplied exponent.

◆ power() [2/2]

FloatingPoint pecunia::FloatingPoint::power ( const std::int64_t & exponent) const
nodiscard

Performs the exponentiation operation.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
DomainErrorWhen the result of the operation would result in a division by zero.
Parameters
exponentThe power to raise the base value to.
Returns
The result of raising the current value, the base, to the power of the supplied exponent.

◆ reciprocal()

FloatingPoint pecunia::FloatingPoint::reciprocal ( ) const
nodiscard

Calculates the reciprocal of the current instance's value.

Exceptions
OverflowErrorWhen the result of the operation would result in an overflow.
UnderflowErrorWhen the result of the operation would result in an underflow.
DomainErrorWhen the result of the operation would result in a division by zero.
Returns
The value of 1 / value.

◆ squareRoot()

FloatingPoint pecunia::FloatingPoint::squareRoot ( ) const
nodiscard

Calculates the square root of the stored value.

Exceptions
DomainErrorWhen the result of the operation would be invalid.
Returns
The result of the square root.

◆ toString()

std::string pecunia::FloatingPoint::toString ( ) const
nodiscard

Converts the float-point value into a string.

Returns
Human readable form of the number.

◆ underlying()

const FloatingPointBase & pecunia::FloatingPoint::underlying ( ) const
nodiscardnoexcept

The unsafe type represented by the floating-point value.