ARTS 2.5.0 (git: 9ee3ac6c)
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
 

Detailed Description

Implements rational numbers to work with other ARTS types.

Definition at line 52 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 59 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]

constexpr Index Rational::Denom ( ) const
inlineconstexprnoexcept

Denominator.

Definition at line 86 of file rational.h.

References mdenom.

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

◆ Denom() [2/3]

constexpr Index & Rational::Denom ( )
inlineconstexprnoexcept

Denominator.

Definition at line 92 of file rational.h.

References mdenom.

◆ Denom() [3/3]

constexpr void Rational::Denom ( Index  x)
inlineconstexprnoexcept

Denominator.

Definition at line 98 of file rational.h.

References mdenom.

◆ fixSign()

constexpr Rational & Rational::fixSign ( )
inlineconstexprnoexcept

Makes the sign of mdenom positive.

Definition at line 328 of file rational.h.

References mdenom, and mnom.

Referenced by operator<<(), and 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 115 of file rational.h.

References isUndefined().

Referenced by isIndex(), operator bool(), and operator==().

◆ 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 123 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 108 of file rational.h.

References mdenom.

Referenced by case_b_g_coefficient_o2(), Absorption::ENUMCLASS(), isDefined(), QuantumFieldDescription::Parse(), and test43().

◆ Nom() [1/3]

constexpr Index Rational::Nom ( ) const
inlineconstexprnoexcept

Nominator.

Definition at line 83 of file rational.h.

References mnom.

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

◆ Nom() [2/3]

constexpr Index & Rational::Nom ( )
inlineconstexprnoexcept

Nominator.

Definition at line 89 of file rational.h.

References mnom.

◆ Nom() [3/3]

constexpr void Rational::Nom ( Index  x)
inlineconstexprnoexcept

Nominator.

Definition at line 95 of file rational.h.

References mnom.

◆ operator bool()

constexpr Rational::operator bool ( ) const
inlineexplicitconstexprnoexcept

Cast to bool.

Definition at line 302 of file rational.h.

References isDefined(), and mnom.

◆ operator Index()

constexpr Rational::operator Index ( ) const
inlineexplicitconstexprnoexcept

Cast to Index.

Definition at line 310 of file rational.h.

References toIndex().

◆ operator int()

constexpr Rational::operator int ( ) const
inlineexplicitconstexprnoexcept

Cast to int.

Definition at line 313 of file rational.h.

References toInt().

◆ operator Numeric()

constexpr Rational::operator Numeric ( ) const
inlineexplicitconstexprnoexcept

Cast to Numeric.

Definition at line 307 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 264 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 274 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 253 of file rational.h.

References a, mdenom, and mnom.

◆ operator++() [1/2]

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

Add one if possible.

Definition at line 290 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 280 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 171 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 181 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 160 of file rational.h.

References a, mdenom, and mnom.

◆ operator--() [1/2]

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

Remove one if possible.

Definition at line 296 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 285 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 202 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 212 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 191 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 233 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 243 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 222 of file rational.h.

References a, mdenom, and mnom.

◆ read()

bifstream & Rational::read ( bifstream bif)
inline

Binary read for Rational.

Definition at line 316 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 104 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 134 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 153 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 142 of file rational.h.

References mdenom, and mnom.

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

◆ write()

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

Binary write for Rational.

Definition at line 322 of file rational.h.

References mdenom, and mnom.

Member Data Documentation

◆ mdenom

◆ mnom


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