rational_field.hpp - Rationals#
-
struct RationalField#
Models some features of a number field with an embedding into the real. In practice you won’t be using instances of this but just use it as a type parameter to specify that a module should be considered over the rationals.
#include <exact-real/rational_field.hpp> #include <exact-real/module.hpp> #include <exact-real/real_number.hpp> #include <gmpxx.h> auto M = exactreal::Module<exactreal::RationalField>::make({exactreal::RealNumber::rational(mpq_class{1, 2})}, exactreal::RationalField{});
Public Types
-
typedef mpq_class ElementClass#
The internal representation of element of this ring, i.e., GMP rationals.
Public Functions
-
RationalField()#
Create the rational field.
-
RationalField(const mpq_class&)#
Create “a” rational field that contains the argument.
This is identical to RationalField::RationalField() but other rings, say number fields, have different rings and need to be able to construct the smallest ring that contains a certain element.
-
ElementClass coerce(const ElementClass &x) const#
Convert the rational argument into this rational field, i.e., just return the rational unchanged.
Number fields need the equivalent of this method to convert elements between different number fields.
-
bool operator==(const RationalField&) const#
Return whether this field is equal to another rational field, i.e.,
true
.exactreal::RationalField{} == exactreal::RationalField{1337} // -> true
Public Static Functions
-
static RationalField compositum(const RationalField &lhs, const RationalField &rhs)#
Return the rational field that contains both arguments.
This is just the RationalField::RationalField() but other rings need such functionality to compute a composite ring.
-
static bool unit(const ElementClass &x)#
Return whether
x
is a unit, i.e., whether it is non-zero.
-
static Arb arb(const ElementClass &x, long prec)#
Return an Arb approximation of the rational
x
.#include <exact-real/arb.hpp> exactreal::RationalField::arb(mpq_class{1, 3}, 64) // -> [0.333333 +/- 3.34e-7]
-
static mpz_class floor(const ElementClass &x)#
Return the integer floor of the rational
x
.
-
static std::optional<mpq_class> rational(const ElementClass &x)#
Return the rational
x
as a rational number, i.e,x
unchanged.
-
template<typename T>
static ElementClass &imul(ElementClass&, const T&)# Multiply the rational
x
witht
.The argument may be a primitive integer, a GMP integer, or a GMP rational.
-
template<typename T>
static ElementClass &idiv(ElementClass&, const T&)# Divide the rational
x
byt
.The argument may be a primitive integer, a GMP integer, or a GMP rational.
-
typedef mpq_class ElementClass#