ARTS  2.4.0(git:4fb77825)
rational.h File Reference

Contains the rational class definition. More...

#include <cassert>
#include <ostream>
#include "array.h"
#include "bifstream.h"
#include "bofstream.h"
#include "math_funcs.h"
#include "matpack.h"

Go to the source code of this file.

Classes

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

Macros

#define RATIONAL_UNDEFINED   Rational(0, 0)
 

Typedefs

typedef Array< RationalArrayOfRational
 

Functions

constexpr Index gcd (Index a, Index b)
 Returns the greatest common denominator of two numbers. More...
 
constexpr Rational reduce_by_gcd (const Rational a)
 Returns the rational reduced by the greates. More...
 
constexpr Rational numeric2rational (Numeric x, size_t maxdec=4)
 Rational from Numeric. More...
 
constexpr Rational operator- (const Rational a)
 Negative. More...
 
constexpr Rational operator+ (const Rational a)
 Positive. More...
 
constexpr Rational operator+ (const Rational a, const Rational b)
 Addition. More...
 
constexpr Rational operator+ (const Rational a, Index b)
 Addition. More...
 
constexpr Rational operator+ (Index b, const Rational a)
 Addition. More...
 
constexpr Rational operator- (const Rational a, const Rational b)
 Subtraction. More...
 
constexpr Rational operator- (const Rational a, Index b)
 Subtraction. More...
 
constexpr Rational operator- (Index b, const Rational a)
 Subtraction. More...
 
constexpr Rational operator/ (const Rational a, const Rational b)
 Division. More...
 
constexpr Rational operator/ (const Rational a, Index b)
 Division. More...
 
constexpr Rational operator/ (Index b, const Rational a)
 Division. More...
 
constexpr Rational operator* (const Rational a, const Rational b)
 Multiplication. More...
 
constexpr Rational operator* (const Rational a, Index b)
 Multiplication. More...
 
constexpr Rational operator* (Index b, const Rational a)
 Multiplication. More...
 
constexpr Rational operator% (const Rational a, const Rational b)
 Remainder. More...
 
constexpr Rational operator% (const Rational a, Index b)
 Remainder. More...
 
constexpr Rational operator% (Index b, const Rational a)
 Remainder. More...
 
constexpr bool operator== (const Rational a, const Rational b)
 Equality. More...
 
constexpr bool operator!= (Rational a, Rational b)
 Inequality. More...
 
constexpr bool operator< (Rational a, Rational b)
 Less than. More...
 
constexpr bool operator> (Rational a, Rational b)
 More than. More...
 
constexpr bool operator<= (Rational a, Rational b)
 Less than or equal to. More...
 
constexpr bool operator>= (const Rational a, const Rational b)
 More than or equal to. More...
 
constexpr bool operator! (const Rational a)
 Not. More...
 
Numeric fac (const Rational r)
 Factorial. More...
 
Numeric sqrt (const Rational r)
 Square root. More...
 
Numeric pow (const Rational base, Numeric exp)
 Power of. More...
 
Numeric pow (Numeric base, const Rational exp)
 Power of. More...
 
Numeric pow (const Rational base, const Rational exp)
 Power of. More...
 
std::ostream & operator<< (std::ostream &os, const Rational &a)
 Output operator. More...
 
std::istream & operator>> (std::istream &is, Rational &a)
 Input operator. More...
 
constexpr bool operator< (const Index a, const Rational b)
 less More...
 
constexpr bool operator< (const Rational a, const Index b)
 less More...
 
constexpr bool operator> (const Index a, const Rational b)
 more More...
 
constexpr bool operator> (const Rational a, const Index b)
 more More...
 
constexpr bool operator== (const Rational a, const Index b)
 equal More...
 
constexpr bool operator!= (const Rational a, const Index b)
 not equal More...
 
constexpr Rational abs (const Rational a)
 Absolute. More...
 
constexpr Rational max (const Rational a, const Rational b)
 Maximum. More...
 
constexpr Rational operator""_2 (unsigned long long int n)
 Returns common operator n/2. More...
 
constexpr Rational operator""_rat (unsigned long long int n)
 Returns common operator n/1. More...
 
constexpr bool even (const Rational r)
 Returns true if even integer. More...
 

Detailed Description

Contains the rational class definition.

Author
Richard Larsson
Date
2012-10-31

Definition in file rational.h.

Macro Definition Documentation

◆ RATIONAL_UNDEFINED

#define RATIONAL_UNDEFINED   Rational(0, 0)

Definition at line 361 of file rational.h.

Typedef Documentation

◆ ArrayOfRational

Definition at line 737 of file rational.h.

Function Documentation

◆ abs()

constexpr Rational abs ( const Rational  a)
constexpr

Absolute.

Parameters
[in]aAny Rational
Returns
constexpr Rational Absolute value of the Rational

Definition at line 723 of file rational.h.

◆ even()

constexpr bool even ( const Rational  r)
constexpr

Returns true if even integer.

Parameters
[in]rAny rational
Returns
true if r is even, otherwise false

Definition at line 762 of file rational.h.

Referenced by o2_ecs_wigner_symbol_tran(), o2_makarov2013_reduced_dipole(), and Absorption::reduced_magnetic_quadrapole().

◆ fac()

Numeric fac ( const Rational  r)
inline

Factorial.

Parameters
[in]rAny Rational
Returns
Numeric Factorial of the Rational

Definition at line 613 of file rational.h.

References Rational::toIndex().

◆ gcd()

constexpr Index gcd ( Index  a,
Index  b 
)
constexpr

Returns the greatest common denominator of two numbers.

Parameters
[in]anumber a
[in]bnumber b
Returns
num such that Rational(a/num, b/num) is the same as Rational(a, b)

Definition at line 45 of file rational.h.

Referenced by Rational::Rational(), and reduce_by_gcd().

◆ max()

constexpr Rational max ( const Rational  a,
const Rational  b 
)
constexpr

Maximum.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
constexpr Rational Largest of a and b

Definition at line 733 of file rational.h.

◆ numeric2rational()

constexpr Rational numeric2rational ( Numeric  x,
size_t  maxdec = 4 
)
constexpr

Rational from Numeric.

Performs basic rounding

Parameters
[in]xNumeric value
[in]maxdecMaximum number of decimals

Definition at line 330 of file rational.h.

References ARTS::Var::x().

Referenced by Rational::Rational(), and test_numeric2rational().

◆ operator!()

constexpr bool operator! ( const Rational  a)
constexpr

Not.

Parameters
[in]aAny Rational
Returns
true If a.Nom() and a.isDefined()
false Otherwise

Definition at line 606 of file rational.h.

References Rational::isDefined(), and Rational::Nom().

◆ operator!=() [1/2]

constexpr bool operator!= ( const Rational  a,
const Index  b 
)
constexpr

not equal

Parameters
[in]aAny Rational
[in]bAny Index
Returns
True if a is not equal to b

Definition at line 714 of file rational.h.

◆ operator!=() [2/2]

constexpr bool operator!= ( Rational  a,
Rational  b 
)
constexpr

Inequality.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
true If not equal
false Otherwise

Definition at line 553 of file rational.h.

References operator==().

◆ operator""_2()

constexpr Rational operator""_2 ( unsigned long long int  n)
constexpr

Returns common operator n/2.

Parameters
[in]nAny positive integer
Returns
Rational(n, 2)

Definition at line 744 of file rational.h.

◆ operator""_rat()

constexpr Rational operator""_rat ( unsigned long long int  n)
constexpr

Returns common operator n/1.

Parameters
[in]nAny positive integer
Returns
Rational(n, 1)

Definition at line 753 of file rational.h.

◆ operator%() [1/3]

constexpr Rational operator% ( const Rational  a,
const Rational  b 
)
constexpr

Remainder.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
constexpr Rational a % b

Definition at line 507 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator%() [2/3]

constexpr Rational operator% ( const Rational  a,
Index  b 
)
constexpr

Remainder.

Parameters
[in]aAny Rational
[in]bAny Index
Returns
constexpr Rational a % b

Definition at line 520 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator%() [3/3]

constexpr Rational operator% ( Index  b,
const Rational  a 
)
constexpr

Remainder.

Parameters
[in]bAny Index
[in]aAny Rational
Returns
constexpr Rational b % a

Definition at line 530 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator*() [1/3]

constexpr Rational operator* ( const Rational  a,
const Rational  b 
)
constexpr

Multiplication.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
constexpr Rational a * b

Definition at line 479 of file rational.h.

References Rational::Denom(), and Rational::Nom().

Referenced by operator*().

◆ operator*() [2/3]

constexpr Rational operator* ( const Rational  a,
Index  b 
)
constexpr

Multiplication.

Parameters
[in]aAny Rational
[in]bAny Index
Returns
constexpr Rational a * b

Definition at line 489 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator*() [3/3]

constexpr Rational operator* ( Index  b,
const Rational  a 
)
constexpr

Multiplication.

Parameters
[in]bAny Index
[in]aAny Rational
Returns
constexpr Rational a * b

Definition at line 499 of file rational.h.

References operator*().

◆ operator+() [1/4]

constexpr Rational operator+ ( const Rational  a)
constexpr

Positive.

Parameters
[in]aAny Rational
Returns
constexpr Rational a

Definition at line 377 of file rational.h.

Referenced by operator+().

◆ operator+() [2/4]

constexpr Rational operator+ ( const Rational  a,
const Rational  b 
)
constexpr

Addition.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
constexpr Rational a + b

Definition at line 385 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator+() [3/4]

constexpr Rational operator+ ( const Rational  a,
Index  b 
)
constexpr

Addition.

Parameters
[in]aAny Rational
[in]bAny Index
Returns
constexpr Rational a + b

Definition at line 398 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator+() [4/4]

constexpr Rational operator+ ( Index  b,
const Rational  a 
)
constexpr

Addition.

Parameters
[in]bAny Index
[in]aAny Rational
Returns
constexpr Rational a + b

Definition at line 408 of file rational.h.

References operator+().

◆ operator-() [1/4]

constexpr Rational operator- ( const Rational  a)
constexpr

Negative.

Parameters
[in]aAny Rational
Returns
constexpr Rational Negative a

Definition at line 368 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator-() [2/4]

constexpr Rational operator- ( const Rational  a,
const Rational  b 
)
constexpr

Subtraction.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
constexpr Rational a - b

Definition at line 416 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator-() [3/4]

constexpr Rational operator- ( const Rational  a,
Index  b 
)
constexpr

Subtraction.

Parameters
[in]aAny Rational
[in]bAny Index
Returns
constexpr Rational a - b

Definition at line 429 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator-() [4/4]

constexpr Rational operator- ( Index  b,
const Rational  a 
)
constexpr

Subtraction.

Parameters
[in]bAny Index
[in]aAny Rational
Returns
constexpr Rational b - a

Definition at line 439 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator/() [1/3]

constexpr Rational operator/ ( const Rational  a,
const Rational  b 
)
constexpr

Division.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
constexpr Rational a / b

Definition at line 449 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator/() [2/3]

constexpr Rational operator/ ( const Rational  a,
Index  b 
)
constexpr

Division.

Parameters
[in]aAny Rational
[in]bAny Index
Returns
constexpr Rational a / b

Definition at line 459 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator/() [3/3]

constexpr Rational operator/ ( Index  b,
const Rational  a 
)
constexpr

Division.

Parameters
[in]bAny Index
[in]aAny Rational
Returns
constexpr Rational b / a

Definition at line 469 of file rational.h.

References Rational::Denom(), and Rational::Nom().

◆ operator<() [1/3]

constexpr bool operator< ( const Index  a,
const Rational  b 
)
constexpr

less

Parameters
[in]aAny Index
[in]bAny Rational
Returns
True if a is less than b

Definition at line 664 of file rational.h.

◆ operator<() [2/3]

constexpr bool operator< ( const Rational  a,
const Index  b 
)
constexpr

less

Parameters
[in]aAny Rational
[in]bAny Index
Returns
True if a is less than b

Definition at line 674 of file rational.h.

◆ operator<() [3/3]

constexpr bool operator< ( Rational  a,
Rational  b 
)
constexpr

Less than.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
true If a < b
false Otherwise

Definition at line 564 of file rational.h.

References Rational::Denom(), Rational::isDefined(), and Rational::Nom().

Referenced by operator>(), and operator>=().

◆ operator<<()

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

Output operator.

Definition at line 33 of file rational.cc.

References Rational::Denom(), Rational::fixSign(), Rational::Nom(), and reduce_by_gcd().

◆ operator<=()

constexpr bool operator<= ( Rational  a,
Rational  b 
)
constexpr

Less than or equal to.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
true If a <= b
false Otherwise

Definition at line 585 of file rational.h.

References operator>().

◆ operator==() [1/2]

constexpr bool operator== ( const Rational  a,
const Index  b 
)
constexpr

equal

Parameters
[in]aAny Rational
[in]bAny Index
Returns
True if a is equal to b

Definition at line 704 of file rational.h.

◆ operator==() [2/2]

constexpr bool operator== ( const Rational  a,
const Rational  b 
)
constexpr

Equality.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
true If equal
false Otherwise

Definition at line 541 of file rational.h.

References Rational::Denom(), Rational::isDefined(), and Rational::Nom().

Referenced by operator!=().

◆ operator>() [1/3]

constexpr bool operator> ( const Index  a,
const Rational  b 
)
constexpr

more

Parameters
[in]aAny Index
[in]bAny Rational
Returns
True if a is more than b

Definition at line 684 of file rational.h.

◆ operator>() [2/3]

constexpr bool operator> ( const Rational  a,
const Index  b 
)
constexpr

more

Parameters
[in]aAny Rational
[in]bAny Index
Returns
True if a is more than b

Definition at line 694 of file rational.h.

◆ operator>() [3/3]

constexpr bool operator> ( Rational  a,
Rational  b 
)
constexpr

More than.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
true If a > b
false Otherwise

Definition at line 576 of file rational.h.

References operator<().

Referenced by operator<=().

◆ operator>=()

constexpr bool operator>= ( const Rational  a,
const Rational  b 
)
constexpr

More than or equal to.

Parameters
[in]aAny Rational
[in]bAny Rational
Returns
true If a >= b
false Otherwise

Definition at line 596 of file rational.h.

References operator<().

◆ operator>>()

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

Input operator.

Definition at line 44 of file rational.cc.

References Array< base >::nelem(), and Absorption::nelem().

◆ pow() [1/3]

Numeric pow ( const Rational  base,
const Rational  exp 
)
inline

Power of.

Parameters
[in]baseAny Rational
[in]expAny Rational
Returns
Numeric base to the power of exp

Definition at line 648 of file rational.h.

References pow(), and Rational::toNumeric().

◆ pow() [2/3]

Numeric pow ( const Rational  base,
Numeric  exp 
)
inline

Power of.

Parameters
[in]baseAny Rational
[in]expAny Numeric
Returns
Numeric base to the power of exp

Definition at line 628 of file rational.h.

References Rational::toNumeric().

Referenced by abs_lookupSetup(), abs_lookupSetupBatch(), abs_lookupSetupWide(), antenna_responseGaussian(), antenna_responseVaryingGaussian(), BF86_CIA_N2(), cart2poslos(), CKD_mt_250_o2_vis(), CKD_mt_v1v0_o2(), conti_n2__(), CP98H2OAbsModel(), diameter_maxFromDiameter_volume_equ(), diameter_volume_equFromDiameter_max(), doit_conv_flagLsq(), ELL07WaterDropletAbs(), TelsemAtlas::emis_interp(), fctl_(), g0Earth(), gaussian_response(), get_ppath_cloudvars(), Ho66_CO2_foreign_continuum(), Ho66_CO2_self_continuum(), binistream::ieee_double2float(), binistream::ieee_single2float(), iyIndependentBeamApproximation(), MaTipping_H2O_foreign_continuum(), mgd(), mgd_with_derivatives(), mod_gamma_dist(), MPM02H2OAbsModel(), MPM85O2AbsModel(), MPM87H2OAbsModel(), MPM87O2AbsModel(), MPM89H2OAbsModel(), MPM89O2AbsModel(), MPM92O2AbsModel(), MPM93_H2O_continuum(), MPM93_N2_continuum(), MPM93_O2_continuum(), MPM93H2OAbsModel(), MPM93IceCrystalAbs(), MPM93O2AbsModel(), MPM93RainExt(), MPM93WaterDropletAbs(), o2_ecs_ql_makarov(), p_gridRefine(), Pardo_ATM_H2O_ForeignContinuum(), Pardo_ATM_N2_dry_continuum(), PFromZSimple(), polynomial_basis_func(), pow(), psd_cloudice_MH97(), psd_mgd_mass_and_something(), psd_rain_W16(), psdModifiedGammaMass(), PWR93O2AbsModel(), PWR98H2OAbsModel(), refellipsoidForAzimuth(), refellipsoidOrbitPlane(), Rosenkranz_CO2_foreign_continuum(), Rosenkranz_CO2_self_continuum(), Rosenkranz_N2_self_continuum(), Rosenkranz_O2_continuum(), rtmethods_jacobian_finalisation(), Standard_H2O_foreign_continuum(), Standard_H2O_self_continuum(), Standard_N2_self_continuum(), Standard_O2_continuum(), surface_specular_R_and_b(), swv_mpmf87s93__(), test07(), transform_x_back(), TRE05O2AbsModel(), yActive(), and yCalc().

◆ pow() [3/3]

Numeric pow ( Numeric  base,
const Rational  exp 
)
inline

Power of.

Parameters
[in]baseAny Numeric
[in]expAny Rational
Returns
Numeric base to the power of exp

Definition at line 638 of file rational.h.

References pow(), and Rational::toNumeric().

◆ reduce_by_gcd()

constexpr Rational reduce_by_gcd ( const Rational  a)
constexpr

Returns the rational reduced by the greates.

Parameters
[in]aAny Rational
Returns
a / gcd(a)

Definition at line 315 of file rational.h.

References Rational::Denom(), gcd(), and Rational::Nom().

Referenced by operator<<(), and Rational::simplify_in_place().

◆ sqrt()

Numeric sqrt ( const Rational  r)
inline

Square root.

Parameters
[in]rAny Rational
Returns
Numeric Square root of the Rational

Definition at line 620 of file rational.h.

References Rational::toNumeric().

Referenced by abs_lookupTestAccMC(), antenna_responseGaussian(), antenna_responseVaryingGaussian(), cart2pol(), cart2poslos(), cart2sph(), cart2zaaa(), case_b_g_coefficient_o2(), cayley_hamilton_fitted_method_4x4_propmat_to_transmat__eigen(), cayley_hamilton_fitted_method_4x4_propmat_to_transmat__explicit(), chk_atm_vecfield_lat90(), complex_n_ice_matzler06(), complex_n_water_liebe93(), compute_transmission_matrix_from_averaged_matrix_at_frequency(), covmat_sxExtractSqrtDiagonal(), distance2D(), distance3D(), doit_conv_flagLsq(), Linefunctions::DopplerConstant(), dotprod_with_los(), MCAntenna::draw_los(), Zeeman::FromGrids(), g_legendre_poly(), g_legendre_poly_deriv(), g_legendre_poly_norm_schmidt(), g_legendre_poly_norm_schmidt_deriv(), g_legendre_poly_norm_schmidt_deriv1(), g_legendre_poly_norm_schmidt_deriv2(), g_legendre_poly_norm_schmidt_deriv3(), g_legendre_poly_norm_schmidt_deriv4(), gaussian_response(), gaussian_response_autogrid(), geompath_l_at_r(), geompath_r_at_l(), geompath_tanpos_3d(), legendre_poly(), legendre_poly_deriv(), legendre_poly_norm_schmidt(), legendre_poly_norm_schmidt_deriv(), los2xyz(), MCGeneral(), o2_ecs_wigner_symbol_tran(), o2_makarov2013_reduced_dipole(), psd_cloudice_MH97(), r_crossing_3d(), ran_gaussian(), TelsemAtlas::read(), Absorption::reduced_magnetic_quadrapole(), refellipsoidForAzimuth(), refellipsoidOrbitPlane(), refr_index_airInfraredEarth(), retrievalErrorsExtract(), Linefunctions::set_htp(), sphdist(), test2(), unitl(), vector_angle(), and yCalc().