ARTS
2.3.1285(git:92a29ea9-dirty)
|
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 numeric2rational(), operator""_2(), operator""_rat(), operator%(), operator*(), operator+(), operator++(), operator-(), operator--(), operator/(), operator<(), operator==(), operator>(), Rational(), and reduce_by_gcd().
|
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 |
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 |
|
inline |
|
inline |
Makes the sign of mdenom positive.
Definition at line 296 of file rational.h.
Referenced by operator<<(), and simplify_in_place().
|
inline |
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==().
|
inline |
Is the object a n-scaled Index.
[in] | n | Scale |
Definition at line 125 of file rational.h.
References isDefined(), mdenom, mnom, and n.
Referenced by toIndex().
|
inline |
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 |
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 |
|
inline |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
|
inlineexplicit |
Multiply by this.
[in] | a | To multiply by |
Definition at line 238 of file rational.h.
References mnom.
|
inline |
Add one if possible.
Definition at line 244 of file rational.h.
References isDefined(), mdenom, mnom, and Rational().
|
inline |
Add to this.
[in] | a | To add |
Definition at line 175 of file rational.h.
|
inline |
Remove one if possible.
Definition at line 251 of file rational.h.
References isDefined(), mdenom, mnom, and Rational().
|
inline |
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().
Referenced by Denom().
|
inline |
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, mnom, and n.
Referenced by fac(), operator Index(), postprocess_group5_hitran(), postprocess_group6_hitran(), postprocess_group6oh_hitran(), and toInt().
|
inline |
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.
Referenced by is_wigner3_ready(), is_wigner6_ready(), o2_ecs_wigner_symbol_tran(), o2_makarov2013_reduced_dipole(), and operator int().
|
inline |
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().