Class List > eosio :: fixed_point32

32 bits representation of Fixed Point class. More...

Public Attributes

Type Name
int32_t val
Value of the fixed point represented as int32_t.

Public Functions

Type Name
fixed_point32 (const fixed_point32< QR > & r)
Construct a new fixed point32 object from another fixed_point32.
fixed_point32 (const fixed_point64< QR > & r)
Construct a new fixed point32 object from another fixed_point64.
fixed_point32 (int32_t param = 0)
Construct a new fixed point32 object.
int32_t int_part () const
To get the integer part of the fixed number.
uint32_t frac_part () const
void print () const
Prints the fixed point value.
fixed_point32 & operator= (const fixed_point32< QR > & r)
Assignment operator.
fixed_point32 & operator= (const fixed_point64< QR > & r)
Assignment operator.
fixed_point32<(Q >QR)?Q:QR > operator+ (const fixed_point32< QR > & r) const
Addition operator.
fixed_point32<(Q >QR)?Q:QR > operator- (const fixed_point32< QR > & r) const
Subtraction operator.
fixed_point64< Q+QR > operator* (const fixed_point32< QR > & r) const
Multiplication operator.
fixed_point64< Q+32-QR > operator/ (const fixed_point32< QR > & r) const
Division operator.
bool operator== (const fixed_point32< QR > & r)
Equality operator.
bool operator> (const fixed_point32< QR > & r)
Greater than operator.
bool operator< (const fixed_point32< QR > & r)
Less than operator.
fixed_point32< Q > & operator= (const fixed_point32< QR > & r)
fixed_point32< Q > & operator= (const fixed_point64< QR > & r)
fixed_point32<(Q >QR)?Q:QR > operator+ (const fixed_point32< QR > & rhs) const
Addition between two fixed_point32 variables and the result goes to fixed_point32.
fixed_point32<(Q >QR)?Q:QR > operator- (const fixed_point32< QR > & rhs) const
Subtraction between two fixed_point32 variables and the result goes to fixed_point32.

Detailed Description

This class is implemented to to replace the floating point variables It can resolve floating point undetermenistic related issues Example:

fixed_point32<17> b(9.654);
fixed_point32<18> c = a*b;
fixed_point32<24> d = a+b+c;
fixed_point32<24> e = b/a;

Public Attributes Documentation

variable val

int32_t eosio::fixed_point32< Q >::val;

Value of the fixed point represented as int32_t.

Value of the fixed point represented as int32_t

Public Functions Documentation

function fixed_point32 (1/3)

template<uint8_t QR>
eosio::fixed_point32< Q >::fixed_point32(
    const fixed_point32< QR > & r
)

Construct a new fixed point32 object from another fixed_point32.

Construct a new fixed point32 object from another fixed_point32

Parameters:

function fixed_point32 (2/3)

template<uint8_t QR>
eosio::fixed_point32< Q >::fixed_point32(
    const fixed_point64< QR > & r
)

Construct a new fixed point32 object from another fixed_point64.

Construct a new fixed point32 object from another fixed_point64. It will be truncated.

Parameters:

function fixed_point32 (3/3)

eosio::fixed_point32< Q >::fixed_point32(
    int32_t param = 0
)

Construct a new fixed point32 object.

Construct a new fixed point32 object from int32_t

Parameters:

  • v - int32_t representation of the fixed point value

function int_part

int32_t eosio::fixed_point32< Q >::int_part() const

To get the integer part of the fixed number.

Get the integer part of the 64 bit fixed number

Returns:

Returns integer part of the fixed number

Example:

fixed_point32<18> a(1234.455667)
std::cout << a.int_part(); // Output: 1234

function frac_part

uint32_t eosio::fixed_point32< Q >::frac_part() const

function print

void eosio::fixed_point32< Q >::print() const

Prints the fixed point value.

Prints the fixed point value

function operator= (1/4)

template<uint8_t QR>
fixed_point32& eosio::fixed_point32< Q >::operator=(
    const fixed_point32< QR > & r
)

Assignment operator.

Assignment operator. Assign fixed_point32 to fixed_point32

Template parameters:

  • qr - Precision of the source

Parameters:

  • r - Source

Returns:

fixed_point32& - Reference to this object

function operator= (2/4)

template<uint8_t QR>
fixed_point32& eosio::fixed_point32< Q >::operator=(
    const fixed_point64< QR > & r
)

Assignment operator.

Assignment operator. Assign fixed_point64 to fixed_point32

Template parameters:

  • qr - Precision of the source

Parameters:

  • r - Source

Returns:

fixed_point32& - Reference to this object

function operator+ (1/2)

template<uint8_t QR>
fixed_point32< (Q>QR)?Q:QR > eosio::fixed_point32< Q >::operator+(
    const fixed_point32< QR > & r
) const

Addition operator.

Addition operator

Template parameters:

  • QR - Precision of the second addend

Parameters:

  • r - Second addend

Returns:

  • The result of addition

function operator- (1/2)

template<uint8_t QR>
fixed_point32< (Q>QR)?Q:QR > eosio::fixed_point32< Q >::operator-(
    const fixed_point32< QR > & r
) const

Subtraction operator.

Subtraction operator

Template parameters:

  • QR - Precision of the minuend

Parameters:

  • r - Minuend

Returns:

  • The result of subtraction

function operator*

template<uint8_t QR>
fixed_point64< Q+QR > eosio::fixed_point32< Q >::operator*(
    const fixed_point32< QR > & r
) const

Multiplication operator.

Multiplication operator for fixed_point32. The result goes to fixed_point64. Multiplication operator

Template parameters:

  • QR - Precision of the multiplier

Parameters:

  • r - Multiplier

Returns:

  • The result of multiplication

Multiplication operator for fixed_point32. The result goes to fixed_point64 Number of decimal on result will be sum of number of decimals of lhs and rhs Example:

fixed_point64<33> result = fixed_point32<0>(131313) / fixed_point32<0>(2323)

function operator/

template<uint8_t QR>
fixed_point64< Q+32-QR > eosio::fixed_point32< Q >::operator/(
    const fixed_point32< QR > & r
) const

Division operator.

Division of two fixed_point32 result will be stored in fixed_point64. Division operator

Template parameters:

  • QR - Precision of the divisor

Parameters:

  • r - Divisor

Returns:

  • The result of division

Division operator for fixed_point32 Example:

fixed_point64<33> result = fixed_point32<0>(131313) / fixed_point32<0>(2323)

function operator==

template<uint8_t QR>
bool eosio::fixed_point32< Q >::operator==(
    const fixed_point32< QR > & r
)

Equality operator.

Equality operator

Template parameters:

  • qr - Precision of the source

Parameters:

  • r - Source

Returns:

true - if equal

Returns:

false - otherwise

function operator>

template<uint8_t QR>
bool eosio::fixed_point32< Q >::operator>(
    const fixed_point32< QR > & r
)

Greater than operator.

Greater than operator

Template parameters:

  • qr - Precision of the source

Parameters:

  • r - Source

Returns:

true - if equal

Returns:

false - otherwise

function operator<

template<uint8_t QR>
bool eosio::fixed_point32< Q >::operator<(
    const fixed_point32< QR > & r
)

Less than operator.

Less than operator

Template parameters:

  • qr - Precision of the source

Parameters:

  • r - Source

Returns:

true - if equal

Returns:

false - otherwise

function operator= (3/4)

template<uint8_t QR>
fixed_point32<Q>& eosio::fixed_point32< Q >::operator=(
    const fixed_point32< QR > & r
)

function operator= (4/4)

template<uint8_t QR>
fixed_point32<Q>& eosio::fixed_point32< Q >::operator=(
    const fixed_point64< QR > & r
)

function operator+ (2/2)

template<uint8_t QR>
fixed_point32< (Q>QR)?Q:QR > eosio::fixed_point32< Q >::operator+(
    const fixed_point32< QR > & rhs
) const

Addition between two fixed_point32 variables and the result goes to fixed_point32.

Addition between two fixed_point32 variables Number of decimal on result will be max of decimals of lhs and rhs

function operator- (2/2)

template<uint8_t QR>
fixed_point32< (Q>QR)?Q:QR > eosio::fixed_point32< Q >::operator-(
    const fixed_point32< QR > & rhs
) const

Subtraction between two fixed_point32 variables and the result goes to fixed_point32.

Subtraction between two fixed_point32 variables Number of decimal on result will be max of decimals of lhs and rhs


The documentation for this class was generated from the following file: libraries/eosiolib/fixedpoint.hpp