ARTS  2.3.1285(git:92a29ea9-dirty)
Rational Class Reference

Implements rational numbers to work with other ARTS types. More...

#include <rational.h>

Public Member Functions

constexpr Rational (const Index nom=0, const Index denom=1)
 Initialization call. More...
 
 Rational (const String &s)
 Initialization call. More...
 
constexpr Index Nom () const
 Nominator. More...
 
constexpr Index Denom () const
 Denominator. More...
 
IndexNom ()
 Nominator. More...
 
IndexDenom ()
 Denominator. More...
 
void Nom (Index x)
 Nominator. More...
 
void Denom (Index x)
 Denominator. More...
 
void simplify_in_place ()
 Simplify by reducing the values locally. More...
 
constexpr bool isUndefined () const
 Is the object not defined. More...
 
constexpr bool isDefined () const
 Is the object defined. More...
 
constexpr bool isIndex (int n=1) const
 Is the object a n-scaled Index. More...
 
constexpr Index toIndex (int n=1) const
 Converts the value to index by n-scaled division. More...
 
constexpr Numeric toNumeric () const
 Converts this to a Numeric. More...
 
constexpr int toInt (int n=1) const
 Converts the value to int by n-scaled division in Index form. More...
 
Rationaloperator+= (const Rational &a)
 Add to this. More...
 
Rationaloperator+= (const Index &a)
 Add to this. More...
 
Rationaloperator-= (const Rational &a)
 Remove from this. More...
 
Rationaloperator-= (const Index &a)
 Remove from this. More...
 
Rationaloperator/= (const Rational &a)
 Divide by this. More...
 
Rationaloperator/= (const Index &a)
 Divide by this. More...
 
Rationaloperator*= (const Rational &a)
 Multiply by this. More...
 
Rationaloperator*= (const Index &a)
 Multiply by this. More...
 
constexpr Rational operator++ (int) const
 Add one if possible. More...
 
constexpr Rational operator-- (int) const
 Remove one if possible. More...
 
Rationaloperator++ ()
 Add one if possible. More...
 
Rationaloperator-- ()
 Remove one if possible. More...
 
constexpr operator bool () const
 Cast to bool. More...
 
constexpr operator Numeric () const
 Cast to Numeric. More...
 
constexpr operator Index () const
 Cast to Index. More...
 
constexpr operator int () const
 Cast to int. More...
 
bifstreamread (bifstream &bif)
 Binary read for Rational. More...
 
bofstreamwrite (bofstream &bof) const
 Binary write for Rational. More...
 
constexpr RationalfixSign ()
 Makes the sign of mdenom positive. More...
 

Private Attributes

Index mnom
 
Index mdenom
 

Detailed Description

Implements rational numbers to work with other ARTS types.

Definition at line 54 of file rational.h.

Constructor & Destructor Documentation

◆ Rational() [1/2]

constexpr Rational::Rational ( const Index  nom = 0,
const Index  denom = 1 
)
inlineexplicit

Initialization call.

Parameters
[in]nomNominator
[in]denomDenominator

Definition at line 61 of file rational.h.

References gcd(), mdenom, and mnom.

Referenced by numeric2rational(), operator""_2(), operator""_rat(), operator%(), operator*(), operator+(), operator++(), operator-(), operator--(), operator/(), operator<(), operator==(), operator>(), Rational(), and reduce_by_gcd().

◆ Rational() [2/2]

Rational::Rational ( const String s)
explicit

Initialization call.

Sets the rational from the string. Formats accepted are

Numeric: 1.234567890 Fraction: 12345/67890 Index: 1234567890

Note that overflow is possible and we do not care to capture it

Parameters
[in]sString of the value

Definition at line 83 of file rational.cc.

References numeric2rational(), Rational(), and RATIONAL_UNDEFINED.

Member Function Documentation

◆ Denom() [1/3]

constexpr Index Rational::Denom ( ) const
inline

◆ Denom() [2/3]

Index& Rational::Denom ( )
inline

Denominator.

Definition at line 94 of file rational.h.

References mdenom.

◆ Denom() [3/3]

void Rational::Denom ( Index  x)
inline

Denominator.

Definition at line 100 of file rational.h.

References mdenom, and simplify_in_place().

◆ fixSign()

constexpr Rational& Rational::fixSign ( )
inline

Makes the sign of mdenom positive.

Definition at line 296 of file rational.h.

References mdenom, and mnom.

Referenced by operator<<(), and simplify_in_place().

◆ isDefined()

constexpr bool Rational::isDefined ( ) const
inline

Is the object defined.

Returns
true If Denom() is not 0
false Otherwise

Definition at line 117 of file rational.h.

References mdenom.

Referenced by isIndex(), operator bool(), operator!(), operator++(), operator--(), operator<(), and operator==().

◆ isIndex()

constexpr bool Rational::isIndex ( int  n = 1) const
inline

Is the object a n-scaled Index.

Parameters
[in]nScale
Returns
true If n*Nom() % Denom() is 0
false Otherwise

Definition at line 125 of file rational.h.

References isDefined(), mdenom, mnom, and n.

Referenced by toIndex().

◆ isUndefined()

constexpr bool Rational::isUndefined ( ) const
inline

Is the object not defined.

Returns
true If Denom() is 0
false Otherwise

Definition at line 110 of file rational.h.

References mdenom.

Referenced by case_b_g_coefficient_o2(), and QuantumFieldDescription::Parse().

◆ Nom() [1/3]

constexpr Index Rational::Nom ( ) const
inline

◆ Nom() [2/3]

Index& Rational::Nom ( )
inline

Nominator.

Definition at line 91 of file rational.h.

References mnom.

◆ Nom() [3/3]

void Rational::Nom ( Index  x)
inline

Nominator.

Definition at line 97 of file rational.h.

References mnom.

◆ operator bool()

constexpr Rational::operator bool ( ) const
inlineexplicit

Cast to bool.

Definition at line 270 of file rational.h.

References isDefined(), and mnom.

◆ operator Index()

constexpr Rational::operator Index ( ) const
inlineexplicit

Cast to Index.

Definition at line 278 of file rational.h.

References toIndex().

◆ operator int()

constexpr Rational::operator int ( ) const
inlineexplicit

Cast to int.

Definition at line 281 of file rational.h.

References toInt().

◆ operator Numeric()

constexpr Rational::operator Numeric ( ) const
inlineexplicit

Cast to Numeric.

Definition at line 275 of file rational.h.

References toNumeric().

◆ operator*=() [1/2]

Rational& Rational::operator*= ( const Rational a)
inline

Multiply by this.

Parameters
[in]aTo multiply by
Returns
Rational& *this

Definition at line 227 of file rational.h.

References Denom(), mdenom, mnom, and Nom().

◆ operator*=() [2/2]

Rational& Rational::operator*= ( const Index a)
inline

Multiply by this.

Parameters
[in]aTo multiply by
Returns
Rational& *this

Definition at line 238 of file rational.h.

References mnom.

◆ operator++() [1/2]

constexpr Rational Rational::operator++ ( int  ) const
inline

Add one if possible.

Definition at line 244 of file rational.h.

References isDefined(), mdenom, mnom, and Rational().

◆ operator++() [2/2]

Rational& Rational::operator++ ( )
inline

Add one if possible.

Definition at line 258 of file rational.h.

References mdenom, and mnom.

◆ operator+=() [1/2]

Rational& Rational::operator+= ( const Rational a)
inline

Add to this.

Parameters
[in]aTo add
Returns
Rational& *this

Definition at line 164 of file rational.h.

References Denom(), mdenom, mnom, and Nom().

◆ operator+=() [2/2]

Rational& Rational::operator+= ( const Index a)
inline

Add to this.

Parameters
[in]aTo add
Returns
Rational& *this

Definition at line 175 of file rational.h.

References mdenom, and mnom.

◆ operator--() [1/2]

constexpr Rational Rational::operator-- ( int  ) const
inline

Remove one if possible.

Definition at line 251 of file rational.h.

References isDefined(), mdenom, mnom, and Rational().

◆ operator--() [2/2]

Rational& Rational::operator-- ( )
inline

Remove one if possible.

Definition at line 264 of file rational.h.

References mdenom, and mnom.

◆ operator-=() [1/2]

Rational& Rational::operator-= ( const Rational a)
inline

Remove from this.

Parameters
[in]aTo remove
Returns
Rational& *this

Definition at line 185 of file rational.h.

References Denom(), mdenom, mnom, and Nom().

◆ operator-=() [2/2]

Rational& Rational::operator-= ( const Index a)
inline

Remove from this.

Parameters
[in]aTo remove
Returns
Rational& *this

Definition at line 196 of file rational.h.

References mdenom, and mnom.

◆ operator/=() [1/2]

Rational& Rational::operator/= ( const Rational a)
inline

Divide by this.

Parameters
[in]aTo divide by
Returns
Rational& *this

Definition at line 206 of file rational.h.

References Denom(), mdenom, mnom, and Nom().

◆ operator/=() [2/2]

Rational& Rational::operator/= ( const Index a)
inline

Divide by this.

Parameters
[in]aTo divide by
Returns
Rational& *this

Definition at line 217 of file rational.h.

References mdenom.

◆ read()

bifstream& Rational::read ( bifstream bif)
inline

Binary read for Rational.

Definition at line 284 of file rational.h.

References mdenom, and mnom.

◆ simplify_in_place()

void Rational::simplify_in_place ( )

Simplify by reducing the values locally.

Definition at line 104 of file rational.cc.

References Denom(), fixSign(), mdenom, mnom, Nom(), and reduce_by_gcd().

Referenced by Denom().

◆ toIndex()

constexpr Index Rational::toIndex ( int  n = 1) const
inline

Converts the value to index by n-scaled division.

Throws a logic error if *this is not an Index

Parameters
[in]nScale to *this
Returns
constexpr Index Of *this

Definition at line 136 of file rational.h.

References isIndex(), mdenom, mnom, and n.

Referenced by fac(), operator Index(), postprocess_group5_hitran(), postprocess_group6_hitran(), postprocess_group6oh_hitran(), and toInt().

◆ toInt()

constexpr int Rational::toInt ( int  n = 1) const
inline

Converts the value to int by n-scaled division in Index form.

Throws a logic error if *this is not an Index

Parameters
[in]nScale to *this
Returns
constexpr int Of *this

Definition at line 157 of file rational.h.

References n, and toIndex().

Referenced by is_wigner3_ready(), is_wigner6_ready(), o2_ecs_wigner_symbol_tran(), o2_makarov2013_reduced_dipole(), and operator int().

◆ toNumeric()

constexpr Numeric Rational::toNumeric ( ) const
inline

Converts this to a Numeric.

Returns
constexpr Numeric of *this

Definition at line 146 of file rational.h.

References mdenom, and mnom.

Referenced by case_b_g_coefficient_o2(), operator Numeric(), pow(), and sqrt().

◆ write()

bofstream& Rational::write ( bofstream bof) const
inline

Binary write for Rational.

Definition at line 290 of file rational.h.

References mdenom, and mnom.

Member Data Documentation

◆ mdenom

◆ mnom


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