5#ifndef LINE_NUM_NUMBER_H
6#define LINE_NUM_NUMBER_H
34#include <boost/multiprecision/cpp_bin_float.hpp>
35#include <boost/multiprecision/cpp_int.hpp>
38#include <boost/multiprecision/gmp.hpp>
39#include <boost/multiprecision/mpfr.hpp>
71 boost::multiprecision::number<boost::multiprecision::gmp_rational, boost::multiprecision::et_off>;
72using BigInt = boost::multiprecision::mpz_int;
73template <
unsigned Digits10>
74using Real = boost::multiprecision::number<boost::multiprecision::mpfr_float_backend<Digits10>>;
76using Rational = boost::multiprecision::number<boost::multiprecision::cpp_rational_backend,
77 boost::multiprecision::et_off>;
78using BigInt = boost::multiprecision::cpp_int;
79template <
unsigned Digits10>
80using Real = boost::multiprecision::number<boost::multiprecision::cpp_bin_float<Digits10>>;
98 if (v == 0)
return -std::numeric_limits<double>::infinity();
100 long bits =
static_cast<long>(boost::multiprecision::msb(a)) + 1;
101 long shift = bits > 53 ? bits - 53 : 0;
103 return std::log(
static_cast<double>(mant)) +
static_cast<double>(shift) * std::log(2.0);
118 static const char*
name() {
return "double"; }
120 static double from_int(
long v) {
return static_cast<double>(v); }
122 return static_cast<double>(num) /
static_cast<double>(den);
128 static std::string
to_string(
const double& v) {
return std::to_string(v); }
136 static const char*
name() {
return "exact"; }
157 static const char*
name() {
return "real"; }
186 for (
unsigned k = 2; k <= n; ++k) f *= num_traits<T>::from_int(
static_cast<long>(k));
T num_factorial(unsigned n)
Factorial as a value of T.
Real< 50 > Real50
Precision tiers offered by the CLI's –arith real:<digits> flag.
T num_pow_int(const T &base, unsigned e)
Integer power, valid in any field (no transcendental requirement).
boost::multiprecision::cpp_int BigInt
boost::multiprecision::number< boost::multiprecision::cpp_rational_backend, boost::multiprecision::et_off > Rational
boost::multiprecision::number< boost::multiprecision::cpp_bin_float< Digits10 > > Real
double log_bigint(const BigInt &v)
log(v) for a positive arbitrary-precision integer.
static const char * name()
static std::string numerator_str(const Rational &v)
static Rational from_int(long v)
static constexpr bool has_transcendental
static std::string to_string(const Rational &v)
static double to_double(const Rational &v)
static Rational from_rational(long num, long den)
static Rational from_double(double v)
Exact: a double is a dyadic rational, so this conversion loses nothing.
static std::string denominator_str(const Rational &v)
static double log_as_double(const Rational &v)
static constexpr bool is_exact
static std::string to_string(const Real< D > &v)
static const char * name()
static constexpr unsigned digits10
static Real< D > from_int(long v)
static Real< D > from_rational(long num, long den)
static Real< D > from_double(double v)
static constexpr bool has_transcendental
static double log_as_double(const Real< D > &v)
static constexpr bool is_exact
static double to_double(const Real< D > &v)
static double from_double(double v)
static std::string to_string(const double &v)
static constexpr bool is_exact
static double log_as_double(const double &v)
log of the value, always returned as a double.
static const char * name()
static double from_int(long v)
static double from_rational(long num, long den)
static constexpr bool has_transcendental
static double to_double(const double &v)