occ
Loading...
Searching...
No Matches
occ::core::Fraction Class Reference

Class representing and holding data a rational number i.e. More...

#include <fraction.h>

Public Member Functions

 Fraction ()=default
 Default constructor 0/1.
 Fraction (int64_t, int64_t)
 Constructor from two ints.
 Fraction (double)
 Constructor from double, will find the nearest representation.
 Fraction (int64_t)
 Constructor from one int i.e. x/1.
 Fraction (const std::string &)
 Constructor from string, will try to parse expressions like x/y.
std::string to_string () const
 represent this fraction as a string
template<typename T>
T cast () const
const Fraction simplify () const
 reduce this fraction by removing common factors in numerator/denominator
const Fraction limit_denominator (int64_t max_denominator=1000000) const
 restrict this fraction to have a maximum denominator (i.e. round it)
const Fraction abs () const
 Absolute value of this fraction.
const Fraction add (const Fraction &other) const
 Add this fraction to another.
const Fraction subtract (const Fraction &other) const
 Subtract another fraction from this fraction.
const Fraction multiply (const Fraction &other) const
 Multiply this fraction with another fraction.
const Fraction divide (const Fraction &other) const
 Divide this fraction by another fraction.
const Fraction operator+ (const Fraction &) const
 operator overload for Fraction::add
const Fraction operator- (const Fraction &) const
 operator overload for Fraction::subtract
const Fraction operator* (const Fraction &) const
 operator overload for Fraction::multiply
const Fraction operator/ (const Fraction &) const
 operator overload for Fraction::divide
auto operator== (const Fraction &) const -> bool
auto operator== (int64_t) const -> bool
auto operator< (const Fraction &) const -> bool
auto operator<= (const Fraction &) const -> bool

Detailed Description

Class representing and holding data a rational number i.e.

Fraction

Constructor & Destructor Documentation

◆ Fraction() [1/5]

occ::core::Fraction::Fraction ( )
default

Default constructor 0/1.

◆ Fraction() [2/5]

occ::core::Fraction::Fraction ( int64_t ,
int64_t  )

Constructor from two ints.

◆ Fraction() [3/5]

occ::core::Fraction::Fraction ( double )

Constructor from double, will find the nearest representation.

◆ Fraction() [4/5]

occ::core::Fraction::Fraction ( int64_t )

Constructor from one int i.e. x/1.

◆ Fraction() [5/5]

occ::core::Fraction::Fraction ( const std::string & )

Constructor from string, will try to parse expressions like x/y.

Member Function Documentation

◆ abs()

const Fraction occ::core::Fraction::abs ( ) const

Absolute value of this fraction.

◆ add()

const Fraction occ::core::Fraction::add ( const Fraction & other) const

Add this fraction to another.

◆ cast()

template<typename T>
T occ::core::Fraction::cast ( ) const
inline

◆ divide()

const Fraction occ::core::Fraction::divide ( const Fraction & other) const

Divide this fraction by another fraction.

◆ limit_denominator()

const Fraction occ::core::Fraction::limit_denominator ( int64_t max_denominator = 1000000) const

restrict this fraction to have a maximum denominator (i.e. round it)

◆ multiply()

const Fraction occ::core::Fraction::multiply ( const Fraction & other) const

Multiply this fraction with another fraction.

◆ operator*()

const Fraction occ::core::Fraction::operator* ( const Fraction & ) const

operator overload for Fraction::multiply

◆ operator+()

const Fraction occ::core::Fraction::operator+ ( const Fraction & ) const

operator overload for Fraction::add

◆ operator-()

const Fraction occ::core::Fraction::operator- ( const Fraction & ) const

operator overload for Fraction::subtract

◆ operator/()

const Fraction occ::core::Fraction::operator/ ( const Fraction & ) const

operator overload for Fraction::divide

◆ operator<()

auto occ::core::Fraction::operator< ( const Fraction & ) const->bool

◆ operator<=()

auto occ::core::Fraction::operator<= ( const Fraction & ) const->bool

◆ operator==() [1/2]

auto occ::core::Fraction::operator== ( const Fraction & ) const->bool

◆ operator==() [2/2]

auto occ::core::Fraction::operator== ( int64_t ) const->bool

◆ simplify()

const Fraction occ::core::Fraction::simplify ( ) const

reduce this fraction by removing common factors in numerator/denominator

◆ subtract()

const Fraction occ::core::Fraction::subtract ( const Fraction & other) const

Subtract another fraction from this fraction.

◆ to_string()

std::string occ::core::Fraction::to_string ( ) const

represent this fraction as a string


The documentation for this class was generated from the following file:
  • /home/runner/work/occ/occ/include/occ/core/fraction.h