ARTS 2.5.9 (git: 825fa5f2)
Rational Struct Reference

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

#include <rational.h>

Public Member Functions

constexpr Rational (const Index n=0, const Index d=1) noexcept
 Initialization call. More...
 
 Rational (const String &s)
 Initialization call. 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 denom positive. More...
 

Public Attributes

Index numer
 
Index denom
 

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  n = 0,
const Index  d = 1 
)
inlineconstexprnoexcept

Initialization call.

Parameters
[in]nomNominator
[in]denomDenominator

Definition at line 52 of file rational.h.

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

Member Function Documentation

◆ fixSign()

constexpr Rational & Rational::fixSign ( )
inlineconstexprnoexcept

Makes the sign of denom positive.

Definition at line 297 of file rational.h.

References denom, and numer.

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

References isUndefined().

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

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

References denom, isDefined(), and numer.

◆ isUndefined()

constexpr bool Rational::isUndefined ( ) const
inlineconstexprnoexcept

Is the object not defined.

Returns
true If Denom() is 0
false Otherwise

Definition at line 77 of file rational.h.

References denom.

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

◆ operator bool()

constexpr Rational::operator bool ( ) const
inlineexplicitconstexprnoexcept

Cast to bool.

Definition at line 271 of file rational.h.

References isDefined(), and numer.

◆ operator Index()

constexpr Rational::operator Index ( ) const
inlineexplicitconstexprnoexcept

Cast to Index.

Definition at line 279 of file rational.h.

References toIndex().

◆ operator int()

constexpr Rational::operator int ( ) const
inlineexplicitconstexprnoexcept

Cast to int.

Definition at line 282 of file rational.h.

References toInt().

◆ operator Numeric()

constexpr Rational::operator Numeric ( ) const
inlineexplicitconstexprnoexcept

Cast to Numeric.

Definition at line 276 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 233 of file rational.h.

References a, and numer.

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

References a, and numer.

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

References a, denom, and numer.

◆ operator++() [1/2]

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

Add one if possible.

Definition at line 259 of file rational.h.

References denom, and numer.

◆ operator++() [2/2]

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

Add one if possible.

Definition at line 249 of file rational.h.

References denom, and numer.

◆ operator+=() [1/3]

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

Add to this.

Parameters
[in]aTo add
Returns
Rational& *this

Definition at line 140 of file rational.h.

References a, denom, and numer.

◆ operator+=() [2/3]

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

Add to this.

Parameters
[in]aTo add
Returns
Rational& *this

Definition at line 150 of file rational.h.

References a, denom, and numer.

◆ operator+=() [3/3]

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

Add to this.

Parameters
[in]aTo add
Returns
Rational& *this

Definition at line 129 of file rational.h.

References a, denom, and numer.

◆ operator--() [1/2]

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

Remove one if possible.

Definition at line 265 of file rational.h.

References denom, and numer.

◆ operator--() [2/2]

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

Remove one if possible.

Definition at line 254 of file rational.h.

References denom, and numer.

◆ operator-=() [1/3]

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

Remove from this.

Parameters
[in]aTo remove
Returns
Rational& *this

Definition at line 171 of file rational.h.

References a, denom, and numer.

◆ operator-=() [2/3]

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

Remove from this.

Parameters
[in]aTo remove
Returns
Rational& *this

Definition at line 181 of file rational.h.

References a, denom, and numer.

◆ operator-=() [3/3]

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

Remove from this.

Parameters
[in]aTo remove
Returns
Rational& *this

Definition at line 160 of file rational.h.

References a, denom, and numer.

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

References a, and denom.

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

References a, and denom.

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

References a, denom, and numer.

◆ read()

bifstream & Rational::read ( bifstream bif)
inline

Binary read for Rational.

Definition at line 285 of file rational.h.

References denom, and numer.

◆ simplify_in_place()

void Rational::simplify_in_place ( )
noexcept

Simplify by reducing the values locally.

Definition at line 86 of file rational.cc.

References a, denom, fixSign(), numer, 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 103 of file rational.h.

References denom, and numer.

Referenced by lm_hitran_2017::calcw(), operator Index(), Absorption::LineMixing::Makarov2020etal::relaxation_matrix_offdiagonal(), 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 122 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 111 of file rational.h.

References denom, and numer.

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

References denom, and numer.

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

◆ denom

◆ numer


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