ARTS  2.3.1285(git:92a29ea9-dirty)
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

Typedef Documentation

◆ ArrayOfRational

Definition at line 737 of file rational.h.

Function Documentation

◆ abs()

constexpr Rational abs ( const Rational  a)

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)

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 
)

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 
)

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 
)

Rational from Numeric.

Performs basic rounding

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

Definition at line 330 of file rational.h.

References i, and Rational::Rational().

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

◆ operator!()

constexpr bool operator! ( const Rational  a)

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!= ( Rational  a,
Rational  b 
)

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/2]

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

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()

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

Returns common operator n/2.

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

Definition at line 744 of file rational.h.

References Rational::Rational().

◆ operator""_rat()

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

Returns common operator n/1.

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

Definition at line 753 of file rational.h.

References Rational::Rational().

◆ operator%() [1/3]

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

Remainder.

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

Definition at line 507 of file rational.h.

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

◆ operator%() [2/3]

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

Remainder.

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

Definition at line 520 of file rational.h.

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

◆ operator%() [3/3]

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

Remainder.

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

Definition at line 530 of file rational.h.

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

◆ operator*() [1/3]

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

Multiplication.

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

Definition at line 479 of file rational.h.

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

Referenced by operator*().

◆ operator*() [2/3]

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

Multiplication.

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

Definition at line 489 of file rational.h.

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

◆ operator*() [3/3]

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

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)

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 
)

Addition.

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

Definition at line 385 of file rational.h.

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

◆ operator+() [3/4]

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

Addition.

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

Definition at line 398 of file rational.h.

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

◆ operator+() [4/4]

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

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)

Negative.

Parameters
[in]aAny Rational
Returns
constexpr Rational Negative a

Definition at line 368 of file rational.h.

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

◆ operator-() [2/4]

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

Subtraction.

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

Definition at line 416 of file rational.h.

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

◆ operator-() [3/4]

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

Subtraction.

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

Definition at line 429 of file rational.h.

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

◆ operator-() [4/4]

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

Subtraction.

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

Definition at line 439 of file rational.h.

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

◆ operator/() [1/3]

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

Division.

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

Definition at line 449 of file rational.h.

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

◆ operator/() [2/3]

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

Division.

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

Definition at line 459 of file rational.h.

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

◆ operator/() [3/3]

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

Division.

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

Definition at line 469 of file rational.h.

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

◆ operator<() [1/3]

constexpr bool operator< ( Rational  a,
Rational  b 
)

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<() [2/3]

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

less

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

Definition at line 664 of file rational.h.

References Rational::Rational().

◆ operator<() [3/3]

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

less

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

Definition at line 674 of file rational.h.

References Rational::Rational().

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

Referenced by pow().

◆ operator<=()

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

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 Rational  b 
)

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==() [2/2]

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

equal

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

Definition at line 704 of file rational.h.

References Rational::Rational().

◆ operator>() [1/3]

constexpr bool operator> ( Rational  a,
Rational  b 
)

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>() [2/3]

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

more

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

Definition at line 684 of file rational.h.

References Rational::Rational().

◆ operator>() [3/3]

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

more

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

Definition at line 694 of file rational.h.

References Rational::Rational().

◆ operator>=()

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

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().

Referenced by pow().

◆ pow() [1/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(), LineShape::SingleSpeciesModel::compute(), LineShape::SingleSpeciesModel::compute_dT(), LineShape::SingleSpeciesModel::compute_dT0(), LineShape::SingleSpeciesModel::compute_dX0(), LineShape::SingleSpeciesModel::compute_dX1(), LineShape::SingleSpeciesModel::compute_dX2(), LineShape::SingleSpeciesModel::compute_dX3(), conti_n2__(), CP98H2OAbsModel(), delanoe_shape_with_derivative(), diameter_maxFromDiameter_volume_equ(), diameter_volume_equFromDiameter_max(), doit_conv_flagLsq(), ELL07WaterDropletAbs(), TelsemAtlas::emis_interp(), fctl_(), g0Earth(), gaussian_response(), get_ppath_cloudvars(), PressureBroadeningData::GetAirAndWaterBroadening(), PressureBroadeningData::GetAirAndWaterBroadening_dForeignExponent(), PressureBroadeningData::GetAirAndWaterBroadening_dForeignGamma(), PressureBroadeningData::GetAirAndWaterBroadening_dForeignPsf(), PressureBroadeningData::GetAirAndWaterBroadening_dSelfExponent(), PressureBroadeningData::GetAirAndWaterBroadening_dSelfGamma(), PressureBroadeningData::GetAirAndWaterBroadening_dSelfPsf(), PressureBroadeningData::GetAirAndWaterBroadening_dWaterExponent(), PressureBroadeningData::GetAirAndWaterBroadening_dWaterGamma(), PressureBroadeningData::GetAirAndWaterBroadening_dWaterPsf(), PressureBroadeningData::GetAirBroadening(), PressureBroadeningData::GetAirBroadening_dForeignExponent(), PressureBroadeningData::GetAirBroadening_dForeignGamma(), PressureBroadeningData::GetAirBroadening_dForeignPsf(), PressureBroadeningData::GetAirBroadening_dSelfExponent(), PressureBroadeningData::GetAirBroadening_dSelfGamma(), PressureBroadeningData::GetHTPAirBroadening(), PressureBroadeningData::GetPressureBroadeningParams_dSelfVMR(), PressureBroadeningData::GetSDAirBroadening(), PressureBroadeningData::GetTestBroadening(), Ho66_CO2_foreign_continuum(), Ho66_CO2_self_continuum(), binistream::ieee_double2float(), binistream::ieee_single2float(), iyIndependentBeamApproximation(), lineshape_doppler(), lon_crossing_3d(), magfield_nk(), 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_MY05(), psd_rain_W16(), psd_snow_F07(), 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() [2/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().

◆ pow() [3/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 operator<<(), operator>>(), pow(), and Rational::toNumeric().

◆ reduce_by_gcd()

constexpr Rational reduce_by_gcd ( const Rational  a)

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(), Rational::Nom(), and Rational::Rational().

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(), faddeeva_algorithm_916(), 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(), hartmann_tran_lineshape(), hui_etal_1978_lineshape(), legendre_poly(), legendre_poly_deriv(), legendre_poly_norm_schmidt(), legendre_poly_norm_schmidt_deriv(), lineshape_doppler(), lineshape_voigt_drayson(), lineshape_voigt_kuntz6(), lon_crossing_3d(), los2xyz(), mc_IWP_cloud_opt_pathCalc(), MCGeneral(), MCIPA(), o2_ecs_wigner_symbol_tran(), o2_makarov2013_reduced_dipole(), psd_cloudice_MH97(), r_crossing_3d(), ran_gaussian(), TelsemAtlas::read(), LineRecord::reduced_magnetic_quadrapole(), Absorption::reduced_magnetic_quadrapole(), refellipsoidForAzimuth(), refellipsoidOrbitPlane(), refr_index_airInfraredEarth(), retrievalErrorsExtract(), LineFunctions::set_faddeeva_algorithm916(), LineFunctions::set_faddeeva_from_full_linemixing(), Linefunctions::set_htp(), LineFunctions::set_htp(), LineFunctions::set_hui_etal_1978(), sphdist(), linalg::std(), test2(), unitl(), vector_angle(), yCalc(), and za_geom2other_point().