Program Listing for File Rational.h
↰ Return to documentation for file (ADS/numeric/Rational.h)
/*--------------------------------------------------------------------------*/
/*---------------------------- File Rational.h -----------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/
#ifndef __ADS_Rational
#define __ADS_Rational
/* self-identification: #endif constant */
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/Contract.h"
#include "ADS/numeric/BigInteger.h"
#include <compare>
#include <string>
#include <utility>
/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace ADS {
/*--------------------------------------------------------------------------*/
/*---------------------------- CLASS Rational ------------------------------*/
/*--------------------------------------------------------------------------*/
class Rational {
/*--------------------------------------------------------------------------*/
public:
Rational( BigInteger num = 0 , BigInteger den = 1 );
[[nodiscard]] const BigInteger & num( void ) const { return( f_num ); }
[[nodiscard]] const BigInteger & den( void ) const { return( f_den ); }
[[nodiscard]] std::string toString( void ) const;
friend Rational operator+( const Rational & a , const Rational & b );
friend Rational operator-( const Rational & a , const Rational & b );
friend Rational operator*( const Rational & a , const Rational & b );
friend Rational operator/( const Rational & a , const Rational & b );
Rational operator-( void ) const;
friend bool operator==( const Rational & a , const Rational & b ) = default;
friend std::strong_ordering operator<=>( const Rational & a ,
const Rational & b );
/*--------------------------------------------------------------------------*/
private:
struct Reduced {};
Rational( BigInteger num , BigInteger den , Reduced );
[[nodiscard]] bool lowest( void ) const;
BigInteger f_num , f_den;
}; // end( class Rational )
/*--------------------------------------------------------------------------*/
} // end( namespace ADS )
/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/numeric/impl/Rational.tpp"
/*--------------------------------------------------------------------------*/
#endif /* Rational.h included */
/*--------------------------------------------------------------------------*/
/*-------------------------- End File Rational.h ---------------------------*/
/*--------------------------------------------------------------------------*/