World Ocean Simulation System (WOSS) library
woss::PDouble Class Reference

Custom precision long double class. More...

#include <custom-precision-double.h>

Collaboration diagram for woss::PDouble:
Collaboration graph

Public Member Functions

 PDouble (const long double input=0.0, const long double precision=PDOUBLE_DEFAULT_PRECISION)
 
 PDouble (const PDouble &copy)
 
 ~PDouble ()
 
void setPrecision (double value)
 
long double getPrecision () const
 
long double getValue () const
 
PDoubleoperator= (const PDouble &copy)
 
 operator int () const
 
 operator float () const
 
 operator double () const
 
 operator long double () const
 
friend::std::ostream & operator<< (::std::ostream &os, const PDouble &instance)
 
friend::std::istream & operator>> (::std::istream &is, PDouble &instance)
 

Static Public Member Functions

static void setDebug (bool flag)
 

Protected Attributes

long double value
 
long double precision
 

Static Protected Attributes

static bool debug = false
 

Friends

const PDouble operator+ (const PDouble &left, const PDouble &right)
 
const PDouble operator- (const PDouble &left, const PDouble &right)
 
const PDouble operator/ (const PDouble &left, const PDouble &right)
 
const PDouble operator* (const PDouble &left, const PDouble &right)
 
const PDouble operator% (const PDouble &left, const PDouble &right)
 
PDoubleoperator+= (PDouble &left, const PDouble &right)
 
PDoubleoperator-= (PDouble &left, const PDouble &right)
 
PDoubleoperator/= (PDouble &left, const PDouble &right)
 
PDoubleoperator*= (PDouble &left, const PDouble &right)
 
PDoubleoperator%= (PDouble &left, const PDouble &right)
 
bool operator== (const PDouble &left, const PDouble &right)
 
bool operator!= (const PDouble &left, const PDouble &right)
 
bool operator> (const PDouble &left, const PDouble &right)
 
bool operator< (const PDouble &left, const PDouble &right)
 
bool operator>= (const PDouble &left, const PDouble &right)
 
bool operator<= (const PDouble &left, const PDouble &right)
 

Detailed Description

Custom precision long double class.

The PDouble class stores a long double value and a long double precision for arithmetic computation and comparison purposes.

Constructor & Destructor Documentation

◆ PDouble() [1/2]

PDouble::PDouble ( const long double  input = 0.0,
const long double  precision = PDOUBLE_DEFAULT_PRECISION 
)

PDouble constructor

Parameters
inputvalue to store
precisioncustom precision

◆ PDouble() [2/2]

PDouble::PDouble ( const PDouble copy)

PDouble copy constructor

Parameters
copyPDouble to be copied

References precision, and value.

◆ ~PDouble()

PDouble::~PDouble ( )

PDouble destructor. It is not virtual, since this class is not meant to be inherited from

Member Function Documentation

◆ getPrecision()

long double woss::PDouble::getPrecision ( ) const
inline

Returns the custom precison

Returns
long double precision

References precision.

◆ getValue()

long double woss::PDouble::getValue ( ) const
inline

Returns the custom value

Returns
long double value

References value.

◆ operator double()

woss::PDouble::operator double ( ) const
inline

double cast operator

Returns
a copy of value casted to double

◆ operator float()

woss::PDouble::operator float ( ) const
inline

float cast operator

Returns
a copy of value casted to float

◆ operator int()

woss::PDouble::operator int ( ) const
inline

int cast operator

Returns
a copy of value casted to int

◆ operator long double()

woss::PDouble::operator long double ( ) const
inline

long double cast operator

Returns
a copy of value casted to long double

◆ operator<<()

friend::std::ostream & woss::PDouble::operator<< ( ::std::ostream &  os,
const PDouble instance 
)

<< operator

Parameters
osleft operand ostream reference
instanceright operand const PDouble reference
Returns
os reference after the operation

◆ operator=()

PDouble & PDouble::operator= ( const PDouble copy)

Assignment operator

Parameters
copyconst reference to a PDouble object to be copied
Returns
PDouble reference to this

References precision, and value.

◆ operator>>()

friend::std::istream & woss::PDouble::operator>> ( ::std::istream &  is,
PDouble instance 
)

‍operator

Parameters
isleft operand istream reference
instanceright operand PDouble reference. It will take the value provided by left with default precision
Returns
is reference after the operation

◆ setDebug()

static void woss::PDouble::setDebug ( bool  flag)
inlinestatic

Sets debug for all instances

Parameters
flagdebug boolean

References debug.

◆ setPrecision()

void woss::PDouble::setPrecision ( double  value)
inline

Sets a custom precison

Parameters
valuedesired precision

References precision, and value.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const PDouble left,
const PDouble right 
)
friend

Inequality operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left != right, false otherwise

◆ operator%

const PDouble operator% ( const PDouble left,
const PDouble right 
)
friend

Modulo operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
a new const instance holding the operation result

◆ operator%=

PDouble & operator%= ( PDouble left,
const PDouble right 
)
friend

Compound assignment modulo operator

Parameters
leftleft operand reference
rightright operand const reference
Returns
left reference after the operation

◆ operator*

const PDouble operator* ( const PDouble left,
const PDouble right 
)
friend

Multiplication operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
a new const instance holding the operation result

◆ operator*=

PDouble & operator*= ( PDouble left,
const PDouble right 
)
friend

Compound assignment multiplication operator

Parameters
leftleft operand reference
rightright operand const reference
Returns
left reference after the operation

◆ operator+

const PDouble operator+ ( const PDouble left,
const PDouble right 
)
friend

Sum operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
a new const instance holding the operation result

◆ operator+=

PDouble & operator+= ( PDouble left,
const PDouble right 
)
friend

Compound assignment sum operator

Parameters
leftleft operand reference
rightright operand const reference
Returns
left reference after the operation

◆ operator-

const PDouble operator- ( const PDouble left,
const PDouble right 
)
friend

Subtraction operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
a new const instance holding the operation result

◆ operator-=

PDouble & operator-= ( PDouble left,
const PDouble right 
)
friend

Compound assignment subtraction operator

Parameters
leftleft operand reference
rightright operand const reference
Returns
left reference after the operation

◆ operator/

const PDouble operator/ ( const PDouble left,
const PDouble right 
)
friend

Division operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
a new const instance holding the operation result

◆ operator/=

PDouble & operator/= ( PDouble left,
const PDouble right 
)
friend

Compound assignment division operator

Parameters
leftleft operand reference
rightright operand const reference
Returns
left reference after the operation

◆ operator<

bool operator< ( const PDouble left,
const PDouble right 
)
friend

Less than operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left < right, false otherwise

◆ operator<=

bool operator<= ( const PDouble left,
const PDouble right 
)
friend

Less than or equal to operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left <= right, false otherwise

◆ operator==

bool operator== ( const PDouble left,
const PDouble right 
)
friend

Equality operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left == right, false otherwise

◆ operator>

bool operator> ( const PDouble left,
const PDouble right 
)
friend

Greater than operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left > right, false otherwise

◆ operator>=

bool operator>= ( const PDouble left,
const PDouble right 
)
friend

Greater than or equal to operator

Parameters
leftleft operand const reference
rightright operand const reference
Returns
true if left >= right, false otherwise

Member Data Documentation

◆ debug

bool PDouble::debug = false
staticprotected

debug status

Referenced by setDebug().

◆ precision

long double woss::PDouble::precision
protected

stored precision

Referenced by getPrecision(), operator=(), PDouble(), and setPrecision().

◆ value

long double woss::PDouble::value
protected

stored value

Referenced by getValue(), operator=(), PDouble(), and setPrecision().


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