Lumiera  0.pre.03
»edit your freedom«
Rational_test Class Reference

Description

Test:
cover some aspects of working with fractional numbers.

Definition at line 54 of file rational-test.cpp.

Private Member Functions

void demonstrate_basics ()
 
virtual void run (Arg)
 
void verify_intLog2 ()
 
void verify_limits ()
 
void verify_requant ()
 

Member Function Documentation

◆ demonstrate_basics()

void demonstrate_basics ( )
inlineprivate
Test:
demonstrate fundamental properties of rational arithmetics as provided by boost::rational
  • represent rational fractions precisely
  • convert to other types and then perform the division
  • our typedef Rat = boost::rational<int64_t>
  • our user-defined literal "_r" to simplify notation
  • string conversion to reveal numerator and denominator
  • automatic normalisation and reduction
  • some typical fractional calculation examples.

Definition at line 79 of file rational-test.cpp.

◆ verify_limits()

void verify_limits ( )
inlineprivate
Test:
demonstrate the limits and perils of rational fractions
  • largest and smallest number representable
  • numeric overflow due to normalisation
  • predicates to check for possible trouble

Definition at line 110 of file rational-test.cpp.

◆ verify_intLog2()

void verify_intLog2 ( )
inlineprivate
Test:
an optimised implementation of integer binary logarithm
  • basically finds the highest bit which is set
  • can be used with various integral types
  • performs better than using the floating-point solution
Todo:
this test (and the implementation) belongs into some basic util header.

Definition at line 199 of file rational-test.cpp.

References util::ilog2().

+ Here is the call graph for this function:

◆ verify_requant()

void verify_requant ( )
inlineprivate
Test:
helper to re-quantise a rational fraction
  • recast a number in terms of another denominator
  • this introduces an error of known limited size
  • and is an option to work around "poisonous" fractions

Definition at line 331 of file rational-test.cpp.

References MAX.

+ Inheritance diagram for Rational_test:
+ Collaboration diagram for Rational_test:

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