Classes Files

Wombat::MamaPrice

More…

#include <MamaPrice.h>

Public Functions

  Name
  MamaPrice()
  MamaPrice(double value, mamaPricePrecision precision =MAMA_PRICE_PREC_100)
  MamaPrice(const MamaPrice & copy)
  ~MamaPrice()
MamaPrice & operator=(const MamaPrice & rhs)
MamaPrice & operator+=(const MamaPrice & rhs)
MamaPrice & operator-=(const MamaPrice & rhs)
bool operator==(const MamaPrice & rhs) const
bool operator==(double rhs) const
bool operator!=(const MamaPrice & rhs) const
bool operator!=(double rhs) const
bool operator<(const MamaPrice & rhs) const
bool operator<(double rhs) const
bool operator>(const MamaPrice & rhs) const
bool operator>(double rhs) const
MamaPrice operator-(const MamaPrice & rhs) const
MamaPrice operator-(double rhs) const
MamaPrice operator-() const
MamaPrice operator+(const MamaPrice & rhs) const
MamaPrice operator+(double rhs) const
double compare(const MamaPrice & rhs) const
void clear()
void set(double priceValue, mamaPriceHints hints =0)
void setValue(double value)
void setPrecision(mamaPricePrecision precision)
void setHints(mamaPriceHints hints)
void setIsValidPrice(bool valid)
double getValue() const
mamaPricePrecision getPrecision() const
mamaPriceHints getHints() const
bool getIsValidPrice() const
void setFromString(const char * str)
void getAsString(char * result, mama_size_t maxLen) const
const char * getAsString() const
void negate()
bool isZero() const
mamaPrice getCValue()
const mamaPrice getCValue() const
mamaPricePrecision decimals2Precision(mama_i32_t places)
mamaPricePrecision denom2Precision(mama_i32_t denominator)
mama_i32_t precision2Decimals(mamaPricePrecision precision)
mama_i32_t precision2Denom(mamaPricePrecision precision)

Detailed Description

class Wombat::MamaPrice;

MamaPrice is a special data type for representing floating point numbers that often require special formatting for display purposes, such as prices. MamaPrice contains the 64-bit (double precision) floating point value and an optional display hint. The set of display hints includes hints for:

  • a number of decimal places,
  • a fractional denominator that are powers of two, and
  • hints for special denominators used in the finance industry (e.g., halves of 32nds).

Public Functions Documentation

function MamaPrice

MamaPrice()

function MamaPrice

MamaPrice(
    double value,
    mamaPricePrecision precision =MAMA_PRICE_PREC_100
)

function MamaPrice

MamaPrice(
    const MamaPrice & copy
)

function ~MamaPrice

~MamaPrice()

function operator=

MamaPrice & operator=(
    const MamaPrice & rhs
)

function operator+=

MamaPrice & operator+=(
    const MamaPrice & rhs
)

function operator-=

MamaPrice & operator-=(
    const MamaPrice & rhs
)

function operator==

bool operator==(
    const MamaPrice & rhs
) const

function operator==

bool operator==(
    double rhs
) const

function operator!=

inline bool operator!=(
    const MamaPrice & rhs
) const

function operator!=

inline bool operator!=(
    double rhs
) const

function operator<

bool operator<(
    const MamaPrice & rhs
) const

function operator<

bool operator<(
    double rhs
) const

function operator>

bool operator>(
    const MamaPrice & rhs
) const

function operator>

bool operator>(
    double rhs
) const

function operator-

inline MamaPrice operator-(
    const MamaPrice & rhs
) const

Subtraction operator. Note: this operator creates a temporary object.

function operator-

inline MamaPrice operator-(
    double rhs
) const

Subtraction operator for double. Note: this operator creates a temporary object.

function operator-

inline MamaPrice operator-() const

Negation operator. Note: this operator creates a temporary object.

function operator+

inline MamaPrice operator+(
    const MamaPrice & rhs
) const

Addition operator. Note: this operator creates a temporary object.

function operator+

inline MamaPrice operator+(
    double rhs
) const

Addition operator for double. Note: this operator creates a temporary object.

function compare

double compare(
    const MamaPrice & rhs
) const

function clear

void clear()

function set

void set(
    double priceValue,
    mamaPriceHints hints =0
)

function setValue

void setValue(
    double value
)

function setPrecision

void setPrecision(
    mamaPricePrecision precision
)

function setHints

void setHints(
    mamaPriceHints hints
)

function setIsValidPrice

void setIsValidPrice(
    bool valid
)

function getValue

double getValue() const

function getPrecision

mamaPricePrecision getPrecision() const

function getHints

mamaPriceHints getHints() const

function getIsValidPrice

bool getIsValidPrice() const

function setFromString

void setFromString(
    const char * str
)

function getAsString

void getAsString(
    char * result,
    mama_size_t maxLen
) const

function getAsString

const char * getAsString() const

Return a string representation of the price. Note that the alternative getAsString() method is more efficient because this method must allocate a temporary buffer (automatically destroyed upon object destruction).

function negate

void negate()

Negate the price value. Hints and precisions are not affected.

function isZero

bool isZero() const

Return whether the price has a value equivalent to zero. It may not be exactly 0.0, but we check against +/- epsilon.

function getCValue

mamaPrice getCValue()

function getCValue

const mamaPrice getCValue() const

function decimals2Precision

static mamaPricePrecision decimals2Precision(
    mama_i32_t places
)

Return the appropriate precision code for a given number of decimal places.

function denom2Precision

static mamaPricePrecision denom2Precision(
    mama_i32_t denominator
)

Return the appropriate precision code for a given fractional denominator.

function precision2Decimals

static mama_i32_t precision2Decimals(
    mamaPricePrecision precision
)

Return the number of decimal places for a given precision code.

function precision2Denom

static mama_i32_t precision2Denom(
    mamaPricePrecision precision
)

Return the fractional denominator for a given precision code.


Updated on 2023-03-31 at 15:29:25 +0100