ARTS  2.4.0(git:4fb77825)
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 
)
inlineexplicitconstexpr

Initialization call.

Parameters
[in]nomNominator
[in]denomDenominator

Definition at line 61 of file rational.h.

References gcd(), mdenom, and mnom.

Referenced by operator++(), operator--(), and Rational().

◆ 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]

Index& Rational::Denom ( )
inline

Denominator.

Definition at line 94 of file rational.h.

References mdenom.

◆ Denom() [2/3]

constexpr Index Rational::Denom ( ) const
inlineconstexpr

◆ Denom() [3/3]

void Rational::Denom ( Index  x)
inline

Denominator.

Definition at line 100 of file rational.h.

References mdenom, and ARTS::Var::x().

◆ fixSign()

constexpr Rational& Rational::fixSign ( )
inlineconstexpr

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
inlineconstexpr

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
inlineconstexpr

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, and mnom.

Referenced by toIndex().

◆ isUndefined()

constexpr bool Rational::isUndefined ( ) const
inlineconstexpr

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]

Index& Rational::Nom ( )
inline

Nominator.

Definition at line 91 of file rational.h.

References mnom.

◆ Nom() [2/3]

constexpr Index Rational::Nom ( ) const
inlineconstexpr

◆ Nom() [3/3]

void Rational::Nom ( Index  x)
inline

Nominator.

Definition at line 97 of file rational.h.

References mnom, and ARTS::Var::x().

◆ operator bool()

constexpr Rational::operator bool ( ) const
inlineexplicitconstexpr

Cast to bool.

Definition at line 270 of file rational.h.

References isDefined(), and mnom.

◆ operator Index()

constexpr Rational::operator Index ( ) const
inlineexplicitconstexpr

Cast to Index.

Definition at line 278 of file rational.h.

References toIndex().

◆ operator int()

constexpr Rational::operator int ( ) const
inlineexplicitconstexpr

Cast to int.

Definition at line 281 of file rational.h.

References toInt().

◆ operator Numeric()

constexpr Rational::operator Numeric ( ) const
inlineexplicitconstexpr

Cast to Numeric.

Definition at line 275 of file rational.h.

References toNumeric().

◆ operator*=() [1/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*=() [2/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++() [1/2]

Rational& Rational::operator++ ( )
inline

Add one if possible.

Definition at line 258 of file rational.h.

References mdenom, and mnom.

◆ operator++() [2/2]

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

Add one if possible.

Definition at line 244 of file rational.h.

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

◆ operator+=() [1/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+=() [2/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--() [1/2]

Rational& Rational::operator-- ( )
inline

Remove one if possible.

Definition at line 264 of file rational.h.

References mdenom, and mnom.

◆ operator--() [2/2]

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

Remove one if possible.

Definition at line 251 of file rational.h.

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

◆ operator-=() [1/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-=() [2/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/=() [1/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.

◆ operator/=() [2/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().

◆ 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().

◆ toIndex()

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

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, and mnom.

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
inlineconstexpr

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 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
inlineconstexpr

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: