Leonardus
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
SOQ Class Reference

Semantic Object Rational Number A multiple precicion rational number. More...

#include <soq.h>

+ Inheritance diagram for SOQ:
+ Collaboration diagram for SOQ:

Public Member Functions

 SOQ ()
 Ctor.
 
 SOQ (const mpq_t p_q)
 Ctor.
 
 SOQ (const __int128 p_num, const __int128 p_den)
 Ctor.
 
 ~SOQ ()
 Dtor.
 
SOQdup () const override
 Creates a new instance as copy following the red book definition. More...
 
std::string opequal () const override
 For operators '=', 'cvs' and 'stack'. More...
 
OTCode ot () const override
 Returns an OTCode. More...
 
std::string type () const override
 Returns a type name. More...
 
bool equal (const SO *p_other) const override
 Equality. More...
 
bool gt (const SO *p_other) const override
 Greater than. More...
 
bool ge (const SO *p_other) const override
 Greater or equal. More...
 
void getRational (mpq_t p_q) const
 Set the parameter to our value.
 
void setRational (const mpq_t p_q)
 Replaces the rational by the parameter.
 
bool getComponents (__int128 &p_num, __int128 &p_den) const
 Set the parameters to numerator and denominator. More...
 
bool isunitfraction () const
 Checks numerator == 1.
 
void divqr (mpq_t p_q, mpq_t p_r) const
 Calculates quotient and remainder.
 
bool parse (std::string p_str)
 Parses the string for a presentation of a rational. More...
 
void abs ()
 Inplace abs.
 
void neg ()
 Inplace neg.
 
void reciprocal ()
 Inplace reciprocal.
 
__float128 flt128 () const
 A real representation of the rational. More...
 
- Public Member Functions inherited from SO
 SO (bool p_exec=false)
 Ctor.
 
virtual ~SO ()=default
 Virtual dtor. More...
 
bool getExec () const
 Getter for exec_.
 
void setExec (bool p_exec)
 Setter for exec_.
 
virtual size_t getSize () const
 Getter for the number of characters or number of objects. More...
 
virtual SOdup () const =0
 Creates a new instance as copy following the red book definition. More...
 
virtual SOclone () const
 Creates a new instance as copy with deep cloning. More...
 
virtual std::string opequal () const =0
 For operators '=', 'cvs' and 'stack'. More...
 
virtual std::string opequalequal () const
 For operators '==' and 'pstack'. More...
 
virtual OTCode ot () const =0
 Returns an OTCode. More...
 
virtual std::string type () const =0
 Returns a type name. More...
 
virtual bool equal (const SO *) const =0
 Equality. More...
 
virtual bool gt (const SO *) const
 Greater than. More...
 
virtual bool ge (const SO *) const
 Greater or equal. More...
 
- Public Member Functions inherited from Counter< SO >
 Counter (Counter< SO > &&)=delete
 
Counter< SO > & operator= (const Counter< SO > &)=delete
 
Counter< SO > & operator= (Counter< SO > &&)=delete
 

Protected Member Functions

bool invariant () const noexcept override
 Checks class invariants. More...
 
- Protected Member Functions inherited from Counter< SO >
 Counter ()
 Ctor.
 
 Counter (const Counter< SO > &)
 Copy ctor.
 
 ~Counter ()
 Dtor.
 
virtual bool invariant () const noexcept
 Checks the invariants of the class in which it is defined. More...
 

Private Member Functions

size_t str_length () const
 Size of the string representation in characters.
 

Private Attributes

mpq_t q_
 The rational number by GMP.
 

Additional Inherited Members

- Static Public Member Functions inherited from Counter< SO >
static size_t getTotalCounter ()
 Static getter for totaly created objects.
 
static size_t getAliveCounter ()
 Static getter for objects alive.
 
static size_t getWatermarkCounter ()
 Static getter for the object counter watermark.
 

Detailed Description

Semantic Object Rational Number A multiple precicion rational number.

Invariant
denominator > 0
gcd of numerator and denominator == 1

Member Function Documentation

◆ dup()

SOQ * SOQ::dup ( ) const
inlineoverridevirtual

Creates a new instance as copy following the red book definition.

Implements SO.

◆ equal()

bool SOQ::equal ( const SO ) const
inlineoverridevirtual

Equality.

Equality means: SOL und SOM are always equal.
For SOD and SOK, share_ptr<> points to the same object.
For SOA, share_ptr<> points to the same object, but empty arrays are equal nonetheless.
For SOO and SOo the function pointer must be the same.
Otherwise the value must be the same, even for SOS with shared_ptr<>.

Returns
bool ... true if the SO's are of the same type and equal
See also
Will be used directly and unchanged as operator eq

Implements SO.

◆ flt128()

__float128 SOQ::flt128 ( ) const

A real representation of the rational.

Returns
__float128 ... the representation as R

◆ ge()

bool SOQ::ge ( const SO ) const
inlineoverridevirtual

Greater or equal.

Will be overwritten for SOI, SOR, SOQ and SOS. The redundancy between equal(), gt() and ge() ist a matter of performance.

Reimplemented from SO.

◆ getComponents()

bool SOQ::getComponents ( __int128 &  p_num,
__int128 &  p_den 
) const
inline

Set the parameters to numerator and denominator.

Returns
bool ... false if the components of the fraction do not fit into __int128

◆ gt()

bool SOQ::gt ( const SO ) const
inlineoverridevirtual

Greater than.

Will be overwritten for SOI, SOR, SOQ and SOS. The redundancy between equal(), gt() and ge() ist a matter of performance.

Reimplemented from SO.

◆ invariant()

bool SOQ::invariant ( ) const
inlineoverrideprotectedvirtualnoexcept

Checks class invariants.

Returns
bool ... Indicates whether the class invariants are maintained.

Reimplemented from DbC.

◆ opequal()

std::string SOQ::opequal ( ) const
inlineoverridevirtual

For operators '=', 'cvs' and 'stack'.

Implements SO.

◆ ot()

OTCode SOQ::ot ( ) const
inlineoverridevirtual

Returns an OTCode.

A "manual" implementation of polymorphism, where C++-polymorphisms fail

Returns
OTCode ... The OTCode of the instance.

Implements SO.

◆ parse()

bool SOQ::parse ( std::string  p_str)
inline

Parses the string for a presentation of a rational.

Accepts two integers separated by a '/'. Accepts a single integer without '/' characters. Ignores whitespaces completely.

Returns
bool ... true if parsing succeeds
Parameters
[in]p_strthe string to be parsed

◆ type()

std::string SOQ::type ( ) const
inlineoverridevirtual

Returns a type name.

Returns
std::string ... The type name of the instance.

Implements SO.


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