ARTS
2.4.0(git:4fb77825)
|
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... | |
Index & | Nom () |
Nominator. More... | |
Index & | Denom () |
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... | |
Rational & | operator+= (const Rational &a) |
Add to this. More... | |
Rational & | operator+= (const Index &a) |
Add to this. More... | |
Rational & | operator-= (const Rational &a) |
Remove from this. More... | |
Rational & | operator-= (const Index &a) |
Remove from this. More... | |
Rational & | operator/= (const Rational &a) |
Divide by this. More... | |
Rational & | operator/= (const Index &a) |
Divide by this. More... | |
Rational & | operator*= (const Rational &a) |
Multiply by this. More... | |
Rational & | operator*= (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... | |
Rational & | operator++ () |
Add one if possible. More... | |
Rational & | operator-- () |
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... | |
bifstream & | read (bifstream &bif) |
Binary read for Rational. More... | |
bofstream & | write (bofstream &bof) const |
Binary write for Rational. More... | |
constexpr Rational & | fixSign () |
Makes the sign of mdenom positive. More... | |
Private Attributes | |
Index | mnom |
Index | mdenom |
Implements rational numbers to work with other ARTS types.
Definition at line 54 of file rational.h.
Initialization call.
[in] | nom | Nominator |
[in] | denom | Denominator |
Definition at line 61 of file rational.h.
References gcd(), mdenom, and mnom.
Referenced by operator++(), operator--(), and Rational().
|
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
[in] | s | String of the value |
Definition at line 83 of file rational.cc.
References numeric2rational(), Rational(), and RATIONAL_UNDEFINED.
|
inline |
|
inlineconstexpr |
Denominator.
Definition at line 88 of file rational.h.
References mdenom.
Referenced by operator%(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator<(), operator<<(), operator==(), reduce_by_gcd(), and simplify_in_place().
|
inline |
|
inlineconstexpr |
Makes the sign of mdenom positive.
Definition at line 296 of file rational.h.
Referenced by operator<<(), and simplify_in_place().
|
inlineconstexpr |
Is the object defined.
Definition at line 117 of file rational.h.
References mdenom.
Referenced by isIndex(), operator bool(), operator!(), operator++(), operator--(), operator<(), and operator==().
|
inlineconstexpr |
Is the object a n-scaled Index.
[in] | n | Scale |
Definition at line 125 of file rational.h.
References isDefined(), mdenom, and mnom.
Referenced by toIndex().
|
inlineconstexpr |
Is the object not defined.
Definition at line 110 of file rational.h.
References mdenom.
Referenced by case_b_g_coefficient_o2(), and QuantumFieldDescription::Parse().
|
inline |
|
inlineconstexpr |
Nominator.
Definition at line 85 of file rational.h.
References mnom.
Referenced by operator!(), operator%(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), operator<(), operator<<(), operator==(), reduce_by_gcd(), and simplify_in_place().
|
inline |
|
inlineexplicitconstexpr |
|
inlineexplicitconstexpr |
|
inlineexplicitconstexpr |
|
inlineexplicitconstexpr |
Multiply by this.
[in] | a | To multiply by |
Definition at line 238 of file rational.h.
References mnom.
|
inline |
|
inlineconstexpr |
Add one if possible.
Definition at line 244 of file rational.h.
References isDefined(), mdenom, mnom, and Rational().
Add to this.
[in] | a | To add |
Definition at line 175 of file rational.h.
|
inline |
|
inlineconstexpr |
Remove one if possible.
Definition at line 251 of file rational.h.
References isDefined(), mdenom, mnom, and Rational().
Remove from this.
[in] | a | To remove |
Definition at line 196 of file rational.h.
Divide by this.
[in] | a | To divide by |
Definition at line 217 of file rational.h.
References mdenom.
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().
|
inlineconstexpr |
Converts the value to index by n-scaled division.
Throws a logic error if *this is not an Index
[in] | n | Scale to *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().
|
inlineconstexpr |
Converts the value to int by n-scaled division in Index form.
Throws a logic error if *this is not an Index
[in] | n | Scale to *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().
|
inlineconstexpr |
Converts this to a Numeric.
Definition at line 146 of file rational.h.
Referenced by case_b_g_coefficient_o2(), operator Numeric(), pow(), and sqrt().
|
private |
Definition at line 307 of file rational.h.
Referenced by Denom(), fixSign(), isDefined(), isIndex(), isUndefined(), operator*=(), operator++(), operator+=(), operator--(), operator-=(), operator/=(), Rational(), read(), simplify_in_place(), toIndex(), toNumeric(), and write().
|
private |
Definition at line 306 of file rational.h.
Referenced by fixSign(), isIndex(), Nom(), operator bool(), operator*=(), operator++(), operator+=(), operator--(), operator-=(), operator/=(), Rational(), read(), simplify_in_place(), toIndex(), toNumeric(), and write().