12 #ifndef INCLUDED_FROM_NUMBERS_H
13 static_assert(
false,
"This file may only be included indirectly by numbers.h");
27 inline bool is_zero(
const cln::cl_RA& n) {
31 inline bool is_one(
const cln::cl_I& n) {
35 inline bool is_one(
const cln::cl_RA& n) {
60 inline cln::cl_I
get_num(
const cln::cl_RA& n) {
61 return cln::numerator(n);
70 return cln::denominator(n);
96 inline std::size_t
bitsize(
const cln::cl_I& n) {
97 return cln::integer_length(n);
104 inline std::size_t
bitsize(
const cln::cl_RA& n) {
114 return cln::double_approx(n);
122 return cln::double_approx(n);
125 template<
typename Integer>
127 template<
typename Integer>
132 assert(n <= std::numeric_limits<sint>::max());
133 assert(n >= std::numeric_limits<sint>::min());
134 return cln::cl_I_to_long(n);
138 assert(n <= std::numeric_limits<uint>::max());
139 assert(n >= std::numeric_limits<uint>::min());
140 return uint(cln::cl_I_to_long(n));
144 template<
typename To,
typename From>
159 return cln::cl_RA(n);
164 return cln::cl_RA(n);
174 inline cln::cl_I to_int<cln::cl_I>(
const cln::cl_RA& n) {
192 inline cln::cl_LF
to_lf(
const cln::cl_RA& n) {
193 return cln::cl_R_to_LF(n, std::max(cln::integer_length(cln::numerator(n)), cln::integer_length(cln::denominator(n))));
200 cln::cl_RA rationalize<cln::cl_RA>(
double n);
203 cln::cl_RA rationalize<cln::cl_RA>(
float n);
206 inline cln::cl_RA rationalize<cln::cl_RA>(
int n) {
207 return cln::cl_RA(n);
211 inline cln::cl_RA rationalize<cln::cl_RA>(
uint n) {
212 return cln::cl_RA(n);
216 inline cln::cl_RA rationalize<cln::cl_RA>(
sint n) {
217 return cln::cl_RA(n);
221 cln::cl_I parse<cln::cl_I>(
const std::string& n);
224 bool try_parse<cln::cl_I>(
const std::string& n, cln::cl_I& res);
227 cln::cl_RA parse<cln::cl_RA>(
const std::string& n);
230 bool try_parse<cln::cl_RA>(
const std::string& n, cln::cl_RA& res);
237 inline cln::cl_I
abs(
const cln::cl_I& n) {
246 inline cln::cl_RA
abs(
const cln::cl_RA& n) {
255 inline cln::cl_I
round(
const cln::cl_RA& n) {
256 return cln::round1(n);
264 inline cln::cl_I
round(
const cln::cl_I& n) {
273 inline cln::cl_I
floor(
const cln::cl_RA& n) {
274 return cln::floor1(n);
282 inline cln::cl_I
floor(
const cln::cl_I& n) {
291 inline cln::cl_I
ceil(
const cln::cl_RA& n) {
292 return cln::ceiling1(n);
300 inline cln::cl_I
ceil(
const cln::cl_I& n) {
310 inline cln::cl_I
gcd(
const cln::cl_I& a,
const cln::cl_I& b) {
321 inline cln::cl_I&
gcd_assign(cln::cl_I& a,
const cln::cl_I& b) {
327 cln::cl_I_div_t res = cln::floor2(dividend, divisor);
340 inline cln::cl_RA&
gcd_assign(cln::cl_RA& a,
const cln::cl_RA& b) {
352 inline cln::cl_RA
gcd(
const cln::cl_RA& a,
const cln::cl_RA& b) {
362 inline cln::cl_I
lcm(
const cln::cl_I& a,
const cln::cl_I& b) {
373 inline cln::cl_RA
lcm(
const cln::cl_RA& a,
const cln::cl_RA& b) {
386 inline cln::cl_RA
pow(
const cln::cl_RA& basis, std::size_t
exp) {
387 return cln::expt(basis,
int(
exp));
390 inline cln::cl_RA
log(
const cln::cl_RA& n) {
393 inline cln::cl_RA
log10(
const cln::cl_RA& n) {
397 inline cln::cl_RA
sin(
const cln::cl_RA& n) {
401 inline cln::cl_RA
cos(
const cln::cl_RA& n) {
415 cln::cl_RA
sqrt(
const cln::cl_RA& a);
426 std::pair<cln::cl_RA, cln::cl_RA>
sqrt_safe(
const cln::cl_RA& a);
435 std::pair<cln::cl_RA, cln::cl_RA>
sqrt_fast(
const cln::cl_RA& a);
445 inline cln::cl_I
mod(
const cln::cl_I& a,
const cln::cl_I& b) {
446 return cln::rem(a, b);
455 inline cln::cl_RA
div(
const cln::cl_RA& a,
const cln::cl_RA& b) {
466 inline cln::cl_I
div(
const cln::cl_I& a,
const cln::cl_I& b) {
468 return cln::exquo(a, b);
478 inline cln::cl_RA&
div_assign(cln::cl_RA& a,
const cln::cl_RA& b) {
491 inline cln::cl_I&
div_assign(cln::cl_I& a,
const cln::cl_I& b) {
493 a = cln::exquo(a, b);
503 inline cln::cl_RA
quotient(
const cln::cl_RA& a,
const cln::cl_RA& b)
514 inline cln::cl_I
quotient(
const cln::cl_I& a,
const cln::cl_I& b)
516 return cln::exquo(a - cln::rem(a, b), b);
526 inline cln::cl_I
remainder(
const cln::cl_I& a,
const cln::cl_I& b) {
527 return cln::rem(a, b);
538 inline cln::cl_I
operator/(
const cln::cl_I& a,
const cln::cl_I& b)
542 inline cln::cl_I
operator/(
const cln::cl_I& lhs,
const int& rhs) {
543 return lhs / cln::cl_I(rhs);
547 return cln::recip(a);
550 std::string
toString(
const cln::cl_RA& _number,
bool _infix=
true);
552 std::string
toString(
const cln::cl_I& _number,
bool _infix=
true);
carl is the main namespace for the library.
double rationalize(double n)
Interval< Number > ceil(const Interval< Number > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
Interval< Number > operator/(const Interval< Number > &lhs, const Number &rhs)
Operator for the division of an interval and a number.
std::pair< cln::cl_RA, cln::cl_RA > sqrt_fast(const cln::cl_RA &a)
Compute square root in a fast but less precise way.
std::string toString(Relation r)
Interval< Number > abs(const Interval< Number > &_in)
Method which returns the absolute value of the passed number.
bool is_positive(const cln::cl_I &n)
Interval< Number > floor(const Interval< Number > &_in)
Method which returns the next smaller integer of this number or the number itself,...
Interval< Number > quotient(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division with remainder.
bool sqrt_exact(const cln::cl_RA &a, cln::cl_RA &b)
Calculate the square root of a fraction if possible.
static const cln::cl_RA ONE_DIVIDED_BY_10_TO_THE_POWER_OF_23
cln::cl_I mod(const cln::cl_I &a, const cln::cl_I &b)
Calculate the remainder of the integer division.
std::pair< cln::cl_RA, cln::cl_RA > root_safe(const cln::cl_RA &a, uint n)
cln::cl_RA reciprocal(const cln::cl_RA &a)
cln::cl_I gcd(const cln::cl_I &a, const cln::cl_I &b)
Calculate the greatest common divisor of two integers.
Interval< Number > exp(const Interval< Number > &i)
cln::cl_RA log10(const cln::cl_RA &n)
bool is_zero(const Interval< Number > &i)
Check if this interval is a point-interval containing 0.
Integer to_int(const Interval< Number > &_floatInterval)
Casts the Interval to an arbitrary integer type which has a constructor for a native int.
cln::cl_I get_num(const cln::cl_RA &n)
Extract the numerator from a fraction.
Interval< Number > cos(const Interval< Number > &i)
Interval< Number > sqrt(const Interval< Number > &i)
uint to_int< uint >(const cln::cl_I &n)
void divide(const cln::cl_I ÷nd, const cln::cl_I &divisor, cln::cl_I "ient, cln::cl_I &remainder)
cln::cl_LF to_lf(const cln::cl_RA &n)
Convert a cln fraction to a cln long float.
static const cln::cl_RA ONE_DIVIDED_BY_10_TO_THE_POWER_OF_52
Interval< Number > div(const Interval< Number > &_lhs, const Interval< Number > &_rhs)
Implements the division which assumes that there is no remainder.
cln::cl_RA & div_assign(cln::cl_RA &a, const cln::cl_RA &b)
Divide two fractions.
Interval< Number > log(const Interval< Number > &i)
bool is_integer(const Interval< Number > &n)
bool is_negative(const cln::cl_I &n)
cln::cl_I get_denom(const cln::cl_RA &n)
Extract the denominator from a fraction.
double to_double(const cln::cl_RA &n)
Converts the given fraction to a double.
cln::cl_I lcm(const cln::cl_I &a, const cln::cl_I &b)
Calculate the least common multiple of two integers.
cln::cl_I round(const cln::cl_RA &n)
Round a fraction to next integer.
Interval< Number > sin(const Interval< Number > &i)
mpq_class gcd(const mpq_class &a, const mpq_class &b)
std::pair< cln::cl_RA, cln::cl_RA > sqrt_safe(const cln::cl_RA &a)
Calculate the square root of a fraction.
mpq_class lcm(const mpq_class &a, const mpq_class &b)
sint to_int< sint >(const cln::cl_I &n)
std::size_t bitsize(const cln::cl_I &n)
Get the bit size of the representation of a integer.
cln::cl_I remainder(const cln::cl_I &a, const cln::cl_I &b)
Calculate the remainder of the integer division.
To from_int(const From &n)
cln::cl_I & gcd_assign(cln::cl_I &a, const cln::cl_I &b)
Calculate the greatest common divisor of two integers.
Interval< Number > pow(const Interval< Number > &i, Integer exp)
bool is_one(const Interval< Number > &i)
Check if this interval is a point-interval containing 1.
auto & get(const std::string &name)