92 [[nodiscard]]
constexpr bool isIndex(
int n=1) const noexcept {
122 [[nodiscard]]
constexpr int toInt(
int n=1) const noexcept {
return int(
toIndex(n)); }
271 explicit constexpr operator bool() const noexcept {
279 explicit constexpr operator Index() const noexcept {
return toIndex(); }
282 explicit constexpr operator int() const noexcept {
return toInt(); }
316 const Index div = gcd(
a.numer,
a.denom);
318 return {
a.numer / div,
a.denom / div};
330 Index nom=0, denom=1;
333 const bool signchange = x < 0;
334 x = signchange ? -x : x;
339 const auto xi=
Index(x);
357#define RATIONAL_UNDEFINED Rational(0, 0)
365 return {-
a.numer,
a.denom};
382 return (
a.denom ==
b.denom)
395 return {
a.numer +
b *
a.denom,
a.denom};
405 return {
a.numer +
b *
a.denom,
a.denom};
431 return (
a.denom ==
b.denom)
444 return {
a.numer -
b *
a.denom,
a.denom};
454 return {
a.numer -
b *
a.denom,
a.denom};
464 return {-
a.numer +
b *
a.denom,
a.denom};
474 return {-
a.numer +
b *
a.denom,
a.denom};
484 return {
a.numer *
b.denom,
a.denom *
b.numer};
494 return {
a.numer,
a.denom *
b};
504 return {
a.numer,
a.denom *
b};
514 return {
a.denom *
b,
a.numer};
524 return {
a.denom *
b,
a.numer};
534 return {
a.numer *
b.numer,
a.denom *
b.denom};
544 return {
a.numer *
b,
a.denom};
554 return {
a.numer *
b,
a.denom};
580 return (
a.denom ==
b.denom)
593 return {
a.numer % (
a.denom *
b),
a.denom};
603 return {
a.numer % (
a.denom *
b),
a.denom};
613 return {(
b *
a.denom) %
a.numer,
a.denom};
623 return {(
b *
a.denom) %
a.numer,
a.denom};
634 return a.isDefined() and
b.isDefined() and
635 a.numer *
b.denom ==
a.denom *
b.numer;
646 return not (
a.isDefined() and
b.isDefined() and
operator==(
a,
b));
657 return a.isDefined() and
b.isDefined() and
658 a.numer *
b.denom <
a.denom *
b.numer;
678 return not
operator>(
a,
b) and
a.isDefined() and
b.isDefined();
689 return not
operator<(
a,
b) and
a.isDefined() and
b.isDefined();
844 return not(
a ==
b) and
a.isDefined();
854 return not(
a ==
b) and
a.isDefined();
863 return a < 0 ? -
a :
a;
873 return a <
b ?
b :
a;
883 return a <
b ?
a :
b;
893constexpr Rational operator ""_2(
unsigned long long int n)
noexcept {
This file contains the definition of Array.
base max(const Array< base > &x)
Max function.
base min(const Array< base > &x)
Min function.
This file contains the class declaration of bifstream.
This file contains the class declaration of bofstream.
This can be used to make arrays out of anything.
Binary output file stream class.
Binary output file stream class.
void abs(Sparse &A, const Sparse &B)
Absolute value of sparse matrix elements.
NUMERIC Numeric
The type to use for all floating point numbers.
INDEX Index
The type to use for all integer numbers and indices.
constexpr bool operator>(const Rational a, const Rational b) noexcept
More than.
constexpr Rational operator+(const Rational a) noexcept
Positive.
constexpr bool operator>=(const Rational a, const Rational b) noexcept
More than or equal to.
Numeric pow(const Rational base, Numeric exp)
Power of.
constexpr bool operator!(const Rational a) noexcept
Not.
constexpr Rational operator-(const Rational a) noexcept
Negative.
constexpr bool operator!=(const Rational a, const Rational b) noexcept
Inequality.
constexpr bool operator<(const Rational a, const Rational b) noexcept
Less than.
Numeric sqrt(const Rational r)
Square root.
constexpr bool iseven(const Rational r) noexcept
Returns true if even integer.
constexpr bool operator==(const Rational a, const Rational b) noexcept
Equality.
constexpr Rational numeric2rational(Numeric x, size_t maxdec=4) noexcept
Rational from Numeric.
constexpr Rational operator%(const Rational a, const Rational b) noexcept
Remainder.
constexpr bool operator<=(const Rational a, const Rational b) noexcept
Less than or equal to.
constexpr Rational reduce_by_gcd(Rational a) noexcept
Returns the rational reduced by the greates.
constexpr Rational operator*(const Rational a, const Rational b) noexcept
Multiplication.
constexpr Rational operator/(const Rational a, const Rational b) noexcept
Division.
Implements rational numbers to work with other ARTS types.
constexpr Rational & operator++() noexcept
Add one if possible.
constexpr bool isUndefined() const noexcept
Is the object not defined.
constexpr Rational & operator-=(const int &a) noexcept
Remove from this.
constexpr Rational(const Index n=0, const Index d=1) noexcept
Initialization call.
constexpr bool isDefined() const noexcept
Is the object defined.
constexpr Rational & operator*=(const int &a) noexcept
Multiply by this.
constexpr Numeric toNumeric() const noexcept
Converts this to a Numeric.
constexpr Rational & operator--() noexcept
Remove one if possible.
constexpr Rational & operator-=(const Index &a) noexcept
Remove from this.
constexpr Rational & operator+=(const Rational &a) noexcept
Add to this.
constexpr Rational & operator/=(const Index &a) noexcept
Divide by this.
constexpr Index toIndex(int n=1) const noexcept
Converts the value to index by n-scaled division.
constexpr Rational & operator+=(const Index &a) noexcept
Add to this.
bifstream & read(bifstream &bif)
Binary read for Rational.
void simplify_in_place() noexcept
Simplify by reducing the values locally.
constexpr Rational & operator*=(const Rational &a) noexcept
Multiply by this.
friend std::ostream & operator<<(std::ostream &os, const Rational &a)
friend std::istream & operator>>(std::istream &is, Rational &a)
constexpr Rational & operator/=(const Rational &a) noexcept
Divide by this.
constexpr Rational & operator+=(const int &a) noexcept
Add to this.
bofstream & write(bofstream &bof) const
Binary write for Rational.
constexpr Rational operator--(int) const noexcept
Remove one if possible.
constexpr Rational & fixSign() noexcept
Makes the sign of denom positive.
constexpr Rational operator++(int) const noexcept
Add one if possible.
constexpr bool isIndex(int n=1) const noexcept
Is the object a n-scaled Index.
constexpr Rational & operator/=(const int &a) noexcept
Divide by this.
constexpr int toInt(int n=1) const noexcept
Converts the value to int by n-scaled division in Index form.
constexpr Rational & operator-=(const Rational &a) noexcept
Remove from this.
constexpr Rational & operator*=(const Index &a) noexcept
Multiply by this.