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

Private Attributes

Index mnom
 
Index mdenom
 

Friends

std::ostream & operator<< (std::ostream &os, const Rational &a)
 
std::istream & operator>> (std::istream &is, Rational &a)
 

Detailed Description

Implements rational numbers to work with other ARTS types.

Definition at line 43 of file rational.h.

Constructor & Destructor Documentation

◆ Rational() [1/2]

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

Initialization call.

Parameters
[in]nomNominator
[in]denomDenominator

Definition at line 50 of file rational.h.

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 57 of file rational.cc.

References a, ARTS_USER_ERROR, b, numeric2rational(), Rational(), and RATIONAL_UNDEFINED.

Member Function Documentation

◆ Denom() [1/3]

constexpr Index Rational::Denom ( ) const
inlineconstexprnoexcept

Denominator.

Definition at line 71 of file rational.h.

References mdenom.

Referenced by test43(), Quantum::Number::Value::Value(), and Quantum::Number::value_holder().

◆ Denom() [2/3]

constexpr Index & Rational::Denom ( )
inlineconstexprnoexcept

Denominator.

Definition at line 77 of file rational.h.

References mdenom.

◆ Denom() [3/3]

constexpr void Rational::Denom ( Index  x)
inlineconstexprnoexcept

Denominator.

Definition at line 83 of file rational.h.

References mdenom.

◆ fixSign()

constexpr Rational & Rational::fixSign ( )
inlineconstexprnoexcept

Makes the sign of mdenom positive.

Definition at line 313 of file rational.h.

References mdenom, and mnom.

Referenced by simplify_in_place().

◆ isDefined()

constexpr bool Rational::isDefined ( ) const
inlineconstexprnoexcept

Is the object defined.

Returns
true If Denom() is not 0
false Otherwise

Definition at line 100 of file rational.h.

References isUndefined().

Referenced by isIndex(), operator bool(), and Absorption::LineMixing::Makarov2020etal::relaxation_matrix_offdiagonal().

◆ isIndex()

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

Is the object a n-scaled Index.

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

Definition at line 108 of file rational.h.

References isDefined(), mdenom, and mnom.

◆ isUndefined()

constexpr bool Rational::isUndefined ( ) const
inlineconstexprnoexcept

Is the object not defined.

Returns
true If Denom() is 0
false Otherwise

Definition at line 93 of file rational.h.

References mdenom.

Referenced by case_b_g_coefficient_o2(), isDefined(), and test43().

◆ Nom() [1/3]

constexpr Index Rational::Nom ( ) const
inlineconstexprnoexcept

Nominator.

Definition at line 68 of file rational.h.

References mnom.

Referenced by test43(), Quantum::Number::Value::Value(), and Quantum::Number::value_holder().

◆ Nom() [2/3]

constexpr Index & Rational::Nom ( )
inlineconstexprnoexcept

Nominator.

Definition at line 74 of file rational.h.

References mnom.

◆ Nom() [3/3]

constexpr void Rational::Nom ( Index  x)
inlineconstexprnoexcept

Nominator.

Definition at line 80 of file rational.h.

References mnom.

◆ operator bool()

constexpr Rational::operator bool ( ) const
inlineexplicitconstexprnoexcept

Cast to bool.

Definition at line 287 of file rational.h.

References isDefined(), and mnom.

◆ operator Index()

constexpr Rational::operator Index ( ) const
inlineexplicitconstexprnoexcept

Cast to Index.

Definition at line 295 of file rational.h.

References toIndex().

◆ operator int()

constexpr Rational::operator int ( ) const
inlineexplicitconstexprnoexcept

Cast to int.

Definition at line 298 of file rational.h.

References toInt().

◆ operator Numeric()

constexpr Rational::operator Numeric ( ) const
inlineexplicitconstexprnoexcept

Cast to Numeric.

Definition at line 292 of file rational.h.

References toNumeric().

◆ operator*=() [1/3]

constexpr Rational & Rational::operator*= ( const Index a)
inlineconstexprnoexcept

Multiply by this.

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

Definition at line 249 of file rational.h.

References a, and mnom.

◆ operator*=() [2/3]

constexpr Rational & Rational::operator*= ( const int &  a)
inlineconstexprnoexcept

Multiply by this.

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

Definition at line 259 of file rational.h.

References a, and mnom.

◆ operator*=() [3/3]

constexpr Rational & Rational::operator*= ( const Rational a)
inlineconstexprnoexcept

Multiply by this.

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

Definition at line 238 of file rational.h.

References a, mdenom, and mnom.

◆ operator++() [1/2]

constexpr Rational & Rational::operator++ ( )
inlineconstexprnoexcept

Add one if possible.

Definition at line 275 of file rational.h.

References mdenom, and mnom.

◆ operator++() [2/2]

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

Add one if possible.

Definition at line 265 of file rational.h.

References mdenom, mnom, and Rational().

◆ operator+=() [1/3]

constexpr Rational & Rational::operator+= ( const Index a)
inlineconstexprnoexcept

Add to this.

Parameters
[in]aTo add
Returns
Rational& *this

Definition at line 156 of file rational.h.

References a, mdenom, and mnom.

◆ operator+=() [2/3]

constexpr Rational & Rational::operator+= ( const int &  a)
inlineconstexprnoexcept

Add to this.

Parameters
[in]aTo add
Returns
Rational& *this

Definition at line 166 of file rational.h.

References a, mdenom, and mnom.

◆ operator+=() [3/3]

constexpr Rational & Rational::operator+= ( const Rational a)
inlineconstexprnoexcept

Add to this.

Parameters
[in]aTo add
Returns
Rational& *this

Definition at line 145 of file rational.h.

References a, mdenom, and mnom.

◆ operator--() [1/2]

constexpr Rational & Rational::operator-- ( )
inlineconstexprnoexcept

Remove one if possible.

Definition at line 281 of file rational.h.

References mdenom, and mnom.

◆ operator--() [2/2]

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

Remove one if possible.

Definition at line 270 of file rational.h.

References mdenom, mnom, and Rational().

◆ operator-=() [1/3]

constexpr Rational & Rational::operator-= ( const Index a)
inlineconstexprnoexcept

Remove from this.

Parameters
[in]aTo remove
Returns
Rational& *this

Definition at line 187 of file rational.h.

References a, mdenom, and mnom.

◆ operator-=() [2/3]

constexpr Rational & Rational::operator-= ( const int &  a)
inlineconstexprnoexcept

Remove from this.

Parameters
[in]aTo remove
Returns
Rational& *this

Definition at line 197 of file rational.h.

References a, mdenom, and mnom.

◆ operator-=() [3/3]

constexpr Rational & Rational::operator-= ( const Rational a)
inlineconstexprnoexcept

Remove from this.

Parameters
[in]aTo remove
Returns
Rational& *this

Definition at line 176 of file rational.h.

References a, mdenom, and mnom.

◆ operator/=() [1/3]

constexpr Rational & Rational::operator/= ( const Index a)
inlineconstexprnoexcept

Divide by this.

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

Definition at line 218 of file rational.h.

References a, and mdenom.

◆ operator/=() [2/3]

constexpr Rational & Rational::operator/= ( const int &  a)
inlineconstexprnoexcept

Divide by this.

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

Definition at line 228 of file rational.h.

References a, and mdenom.

◆ operator/=() [3/3]

constexpr Rational & Rational::operator/= ( const Rational a)
inlineconstexprnoexcept

Divide by this.

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

Definition at line 207 of file rational.h.

References a, mdenom, and mnom.

◆ read()

bifstream & Rational::read ( bifstream bif)
inline

Binary read for Rational.

Definition at line 301 of file rational.h.

References mdenom, and mnom.

◆ simplify_in_place()

void Rational::simplify_in_place ( )
noexcept

Simplify by reducing the values locally.

Definition at line 87 of file rational.cc.

References a, fixSign(), mdenom, mnom, and reduce_by_gcd().

◆ toIndex()

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

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 119 of file rational.h.

References mdenom, and mnom.

Referenced by lm_hitran_2017::calcw(), operator Index(), test43(), and toInt().

◆ toInt()

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

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 138 of file rational.h.

References toIndex().

Referenced by is_wigner3_ready(), is_wigner6_ready(), operator int(), and test43().

◆ toNumeric()

constexpr Numeric Rational::toNumeric ( ) const
inlineconstexprnoexcept

Converts this to a Numeric.

Returns
constexpr Numeric of *this

Definition at line 127 of file rational.h.

References mdenom, and mnom.

Referenced by operator Numeric(), operator*(), operator+(), operator-(), operator/(), pow(), sqrt(), and test43().

◆ write()

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

Binary write for Rational.

Definition at line 307 of file rational.h.

References mdenom, and mnom.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Rational a 
)
friend

Definition at line 34 of file rational.cc.

◆ operator>>

std::istream & operator>> ( std::istream &  is,
Rational a 
)
friend

Definition at line 45 of file rational.cc.

Member Data Documentation

◆ mdenom

◆ mnom


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