LibreOffice Module tools (master) 1
Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
Fraction Class Referencefinal

#include <fract.hxx>

Public Member Functions

 Fraction ()=default
 
 Fraction (const Fraction &rFrac)=default
 
 Fraction (Fraction &&rFrac)=default
 
 Fraction (double dVal)
 
 Fraction (double nNum, double nDen)
 only here to prevent passing of NaN More...
 
 Fraction (sal_Int64 nNum, sal_Int64 nDen)
 
template<typename T1 , typename T2 >
 Fraction (T1 nNum, T2 nDen, typename std::enable_if< std::is_integral< T1 >::value &&std::is_integral< T2 >::value, int >::type=0)
 
bool IsValid () const
 
sal_Int32 GetNumerator () const
 
sal_Int32 GetDenominator () const
 
 operator sal_Int32 () const
 
 operator double () const
 
Fractionoperator= (const Fraction &rfrFrac)=default
 
Fractionoperator= (Fraction &&rfrFrac)=default
 
Fractionoperator= (double v)
 
Fractionoperator+= (const Fraction &rfrFrac)
 
Fractionoperator-= (const Fraction &rfrFrac)
 
Fractionoperator*= (const Fraction &rfrFrac)
 
Fractionoperator/= (const Fraction &rfrFrac)
 
Fractionoperator+= (double v)
 
Fractionoperator-= (double v)
 
Fractionoperator*= (double v)
 
Fractionoperator/= (double v)
 
void ReduceInaccurate (unsigned nSignificantBits)
 
size_t GetHashValue () const
 

Static Public Member Functions

static Fraction MakeFraction (tools::Long nN1, tools::Long nN2, tools::Long nD1, tools::Long nD2)
 Multiply the two fractions represented here and reduce inaccuracy to 32-bits, used by vcl. More...
 

Private Attributes

sal_Int32 mnNumerator = 0
 these two fields form a boost::rational, but I didn't want to put more boost headers into the global space More...
 
sal_Int32 mnDenominator = 1
 
bool mbValid = true
 

Friends

TOOLS_DLLPUBLIC friend Fraction operator+ (const Fraction &rVal1, const Fraction &rVal2)
 
TOOLS_DLLPUBLIC friend Fraction operator- (const Fraction &rVal1, const Fraction &rVal2)
 
TOOLS_DLLPUBLIC friend Fraction operator* (const Fraction &rVal1, const Fraction &rVal2)
 
TOOLS_DLLPUBLIC friend Fraction operator/ (const Fraction &rVal1, const Fraction &rVal2)
 
TOOLS_DLLPUBLIC friend bool operator== (const Fraction &rVal1, const Fraction &rVal2)
 
TOOLS_DLLPUBLIC friend bool operator!= (const Fraction &rVal1, const Fraction &rVal2)
 
TOOLS_DLLPUBLIC friend bool operator< (const Fraction &rVal1, const Fraction &rVal2)
 
TOOLS_DLLPUBLIC friend bool operator> (const Fraction &rVal1, const Fraction &rVal2)
 
TOOLS_DLLPUBLIC friend bool operator<= (const Fraction &rVal1, const Fraction &rVal2)
 
TOOLS_DLLPUBLIC friend bool operator>= (const Fraction &rVal1, const Fraction &rVal2)
 

Detailed Description

Definition at line 30 of file fract.hxx.

Constructor & Destructor Documentation

◆ Fraction() [1/7]

Fraction::Fraction ( )
default

Referenced by MakeFraction().

◆ Fraction() [2/7]

Fraction::Fraction ( const Fraction rFrac)
default

◆ Fraction() [3/7]

Fraction::Fraction ( Fraction &&  rFrac)
default

◆ Fraction() [4/7]

Fraction::Fraction ( double  dVal)
explicit

Definition at line 100 of file fract.cxx.

References mbValid, mnDenominator, mnNumerator, rational_FromDouble(), SAL_WARN, and v.

◆ Fraction() [5/7]

Fraction::Fraction ( double  nNum,
double  nDen 
)

only here to prevent passing of NaN

Definition at line 96 of file fract.cxx.

◆ Fraction() [6/7]

Fraction::Fraction ( sal_Int64  nNum,
sal_Int64  nDen 
)

Definition at line 58 of file fract.cxx.

References isOutOfRange(), mbValid, mnDenominator, mnNumerator, and SAL_WARN_IF.

◆ Fraction() [7/7]

template<typename T1 , typename T2 >
Fraction::Fraction ( T1  nNum,
T2  nDen,
typename std::enable_if< std::is_integral< T1 >::value &&std::is_integral< T2 >::value, int >::type  = 0 
)
inline

Definition at line 44 of file fract.hxx.

Member Function Documentation

◆ GetDenominator()

sal_Int32 Fraction::GetDenominator ( ) const

Definition at line 292 of file fract.cxx.

References mbValid, mnDenominator, and SAL_WARN.

Referenced by tools::GenericTypeSerializer::writeFraction().

◆ GetHashValue()

size_t Fraction::GetHashValue ( ) const

Definition at line 481 of file fract.cxx.

References o3tl::hash_combine(), mbValid, mnDenominator, and mnNumerator.

◆ GetNumerator()

sal_Int32 Fraction::GetNumerator ( ) const

Definition at line 282 of file fract.cxx.

References mbValid, mnNumerator, and SAL_WARN.

Referenced by tools::GenericTypeSerializer::writeFraction().

◆ IsValid()

bool Fraction::IsValid ( ) const
inline

Definition at line 49 of file fract.hxx.

References mbValid.

Referenced by tools::GenericTypeSerializer::writeFraction().

◆ MakeFraction()

Fraction Fraction::MakeFraction ( tools::Long  nN1,
tools::Long  nN2,
tools::Long  nD1,
tools::Long  nD2 
)
static

Multiply the two fractions represented here and reduce inaccuracy to 32-bits, used by vcl.

Definition at line 490 of file fract.cxx.

References a, Fraction(), i, SAL_WARN, and toRational().

◆ operator double()

Fraction::operator double ( ) const
explicit

Definition at line 115 of file fract.cxx.

References mbValid, SAL_WARN, and toRational().

◆ operator sal_Int32()

Fraction::operator sal_Int32 ( ) const
explicit

Definition at line 302 of file fract.cxx.

References mbValid, SAL_WARN, and toRational().

◆ operator*=() [1/2]

Fraction & Fraction::operator*= ( const Fraction rfrFrac)

Definition at line 203 of file fract.cxx.

References a, mbValid, mnDenominator, mnNumerator, SAL_WARN, and toRational().

◆ operator*=() [2/2]

Fraction & Fraction::operator*= ( double  v)
inline

Definition at line 70 of file fract.hxx.

References operator*=(), and v.

Referenced by operator*=().

◆ operator+=() [1/2]

Fraction & Fraction::operator+= ( const Fraction rfrFrac)

Definition at line 130 of file fract.cxx.

References a, mbValid, mnDenominator, mnNumerator, SAL_WARN, and toRational().

◆ operator+=() [2/2]

Fraction & Fraction::operator+= ( double  v)
inline

Definition at line 68 of file fract.hxx.

References operator+=(), and v.

Referenced by operator+=().

◆ operator-=() [1/2]

Fraction & Fraction::operator-= ( const Fraction rfrFrac)

Definition at line 149 of file fract.cxx.

References a, mbValid, mnDenominator, mnNumerator, SAL_WARN, and toRational().

◆ operator-=() [2/2]

Fraction & Fraction::operator-= ( double  v)
inline

Definition at line 69 of file fract.hxx.

References operator-=(), and v.

Referenced by operator-=().

◆ operator/=() [1/2]

Fraction & Fraction::operator/= ( const Fraction rfrFrac)

Definition at line 228 of file fract.cxx.

References a, mbValid, mnDenominator, mnNumerator, SAL_WARN, and toRational().

◆ operator/=() [2/2]

Fraction & Fraction::operator/= ( double  v)
inline

Definition at line 71 of file fract.hxx.

References operator/=(), and v.

Referenced by operator/=().

◆ operator=() [1/3]

Fraction & Fraction::operator= ( const Fraction rfrFrac)
default

◆ operator=() [2/3]

Fraction & Fraction::operator= ( double  v)
inline

Definition at line 62 of file fract.hxx.

References operator=(), and v.

Referenced by operator=().

◆ operator=() [3/3]

Fraction & Fraction::operator= ( Fraction &&  rfrFrac)
default

◆ ReduceInaccurate()

void Fraction::ReduceInaccurate ( unsigned  nSignificantBits)

Friends And Related Function Documentation

◆ operator!=

TOOLS_DLLPUBLIC friend bool operator!= ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 340 of file fract.cxx.

◆ operator*

TOOLS_DLLPUBLIC friend Fraction operator* ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 326 of file fract.cxx.

◆ operator+

TOOLS_DLLPUBLIC friend Fraction operator+ ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 312 of file fract.cxx.

◆ operator-

TOOLS_DLLPUBLIC friend Fraction operator- ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 319 of file fract.cxx.

◆ operator/

TOOLS_DLLPUBLIC friend Fraction operator/ ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 333 of file fract.cxx.

◆ operator<

TOOLS_DLLPUBLIC friend bool operator< ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 366 of file fract.cxx.

◆ operator<=

TOOLS_DLLPUBLIC friend bool operator<= ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 345 of file fract.cxx.

◆ operator==

TOOLS_DLLPUBLIC friend bool operator== ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 355 of file fract.cxx.

◆ operator>

TOOLS_DLLPUBLIC friend bool operator> ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 377 of file fract.cxx.

◆ operator>=

TOOLS_DLLPUBLIC friend bool operator>= ( const Fraction rVal1,
const Fraction rVal2 
)
friend

Definition at line 350 of file fract.cxx.

Member Data Documentation

◆ mbValid

bool Fraction::mbValid = true
private

◆ mnDenominator

sal_Int32 Fraction::mnDenominator = 1
private

◆ mnNumerator

sal_Int32 Fraction::mnNumerator = 0
private

these two fields form a boost::rational, but I didn't want to put more boost headers into the global space

Definition at line 33 of file fract.hxx.

Referenced by Fraction(), GetHashValue(), GetNumerator(), operator*=(), operator+=(), operator-=(), operator/=(), and ReduceInaccurate().


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