30#ifndef BERTINI_NUM_TRAITS_HPP
31#define BERTINI_NUM_TRAITS_HPP
80 return static_cast<unsigned>(ceil(-log10(tol)));
87 return boost::lexical_cast<double>(s);
121 return boost::lexical_cast<complex_dbl>(s);
128 return complex_dbl(boost::lexical_cast<double>(s),boost::lexical_cast<double>(t));
190 std::stringstream err_msg;
191 err_msg <<
"trying to change precision of a double to " << prec;
192 throw std::runtime_error(err_msg.str());
215 std::stringstream err_msg;
216 err_msg <<
"trying to change precision of a double to " << prec;
217 throw std::runtime_error(err_msg.str());
236 return returnme / sqrt( abs(returnme));
247 return returnme / abs(returnme);
278 template <
typename NumberType>
329 return b.convert_to<
unsigned int>();
403 bool negative =
false;
404 if (!s.empty() && s[0] ==
'-') { negative =
true; s = s.substr(1); }
405 else if (!s.empty() && s[0] ==
'+') { s = s.substr(1); }
408 auto e_pos = s.find_first_of(
"eE");
409 if (e_pos != std::string::npos) {
410 exp_shift = std::stoi(s.substr(e_pos + 1));
411 s = s.substr(0, e_pos);
414 auto dot_pos = s.find(
'.');
415 int decimal_places = 0;
416 if (dot_pos != std::string::npos) {
417 decimal_places =
static_cast<int>(s.size()) -
static_cast<int>(dot_pos) - 1;
421 if (s.empty() || s.find_first_not_of(
'0') == std::string::npos) {
424 s = s.substr(s.find_first_not_of(
'0'));
427 if (negative) numer = -numer;
429 int net_exp = decimal_places - exp_shift;
432 for (
int i = 0; i < net_exp; ++i) denom *= 10;
434 }
else if (net_exp < 0) {
436 for (
int i = 0; i < -net_exp; ++i) mult *= 10;
Dependency-free declarations of the pinned draw primitives (ADR-0044).
The main multiprecision complex number type.
complex RandomUnit()
Produce a random unit-modulus complex number, to default precision.
Definition random.hpp:315
double DrawSymmetricDouble()
A draw from this thread's pinned stream, uniform on [-1,1].
Definition algorithm_builder.hpp:36
complex_dbl rand_complex()
Get a random double-precision complex number (not unit modulus; see RandomUnit).
Definition num_traits.hpp:223
constexpr unsigned DoublePrecision()
The number of digits considered "double precision" (16).
Definition num_traits.hpp:152
std::complex< double > complex_dbl
The double-precision complex number type.
Definition double_extensions.hpp:47
T RandomUnit()
Get a random complex number of unit modulus, in number type T.
boost::multiprecision::number< boost::multiprecision::backends::gmp_int, boost::multiprecision::et_on > mpz_int
The arbitrary-precision integer type.
Definition mpfr_extensions.hpp:54
unsigned PrecisionIncrement()
The number of digits by which adaptive precision is increased at each step.
Definition num_traits.hpp:145
real_mp RandomUnit< real_mp >()
Get a random multiprecision real number of unit modulus (i.e.
Definition num_traits.hpp:263
NumberType RandomOrthonormalSeed()
The entry a random orthonormal matrix is seeded with before its QR factorization: a unit draw for the...
Definition num_traits.hpp:280
real_mp RandomOrthonormalSeed< real_mp >()
A real orthonormal seed entry: uniform on [-1, 1], never a bare sign.
Definition num_traits.hpp:288
double NumErrorT
The numeric type used to hold error/tolerance magnitudes throughout Bertini2 – tracking tolerances,...
Definition num_traits.hpp:48
constexpr unsigned MaxPrecisionAllowed()
The maximum precision (digits) the library will escalate to.
Definition num_traits.hpp:166
bmp::number< mpc_complex_backend< 0 >, bmp::et_on > complex_mp
The arbitrary-precision complex number type.
Definition mpfr_complex.hpp:58
boost::multiprecision::number< boost::multiprecision::mpfr_float_backend< 0 >, boost::multiprecision::et_on > real_mp
The arbitrary-precision real number type.
Definition mpfr_extensions.hpp:53
complex_mp RandomUnit< complex_mp >()
Get a random multiprecision complex number of unit modulus.
Definition num_traits.hpp:253
constexpr unsigned LowestMultiplePrecision()
The lowest multiple-precision digit count used (20).
Definition num_traits.hpp:159
unsigned ThreadPrecision()
Get the current thread's precision (digits).
Definition mpfr_complex.hpp:183
boost::multiprecision::number< boost::multiprecision::backends::gmp_rational, boost::multiprecision::et_on > mpq_rational
The exact rational number type.
Definition mpfr_extensions.hpp:55
unsigned Precision(Eigen::MatrixBase< Derived > const &v)
Get the precision of an Eigen object.
Definition eigen_extensions.hpp:339
complex_dbl RandomUnit< complex_dbl >()
Get a random double-precision complex number of unit modulus.
Definition num_traits.hpp:241
stuff for generating random numbers
double Real
The real companion type.
Definition num_traits.hpp:138
complex_dbl Complex
The complex companion type.
Definition num_traits.hpp:139
static complex_dbl FromRational(mpq_rational const &n, unsigned)
Convert an exact rational to a complex double (precision ignored).
Definition num_traits.hpp:133
static unsigned NumDigits()
The number of significant digits (16).
Definition num_traits.hpp:106
static complex_dbl FromString(std::string const &s, std::string const &t)
Build a complex number from real and imaginary string parts.
Definition num_traits.hpp:126
static unsigned NumFuzzyDigits()
The number of digits to trust for fuzzy comparisons.
Definition num_traits.hpp:112
static complex_dbl FromString(std::string const &s)
Parse a complex number from a single string.
Definition num_traits.hpp:119
static complex_mp FromString(std::string const &s)
Parse a complex number from a single string.
Definition num_traits.hpp:363
static unsigned NumDigits()
The number of significant digits (the current thread precision).
Definition num_traits.hpp:356
static complex_mp FromRational(mpq_rational const &n, unsigned precision)
Convert an exact rational to a multiprecision complex number at the given precision.
Definition num_traits.hpp:377
real_mp Real
The real companion type.
Definition num_traits.hpp:382
static complex_mp FromString(std::string const &s, std::string const &t)
Build a complex number from real and imaginary string parts.
Definition num_traits.hpp:370
complex_mp Complex
The complex companion type.
Definition num_traits.hpp:383
static unsigned NumFuzzyDigits()
The number of digits to trust for fuzzy comparisons.
Definition num_traits.hpp:71
double Real
The real companion type.
Definition num_traits.hpp:97
static unsigned TolToDigits(NumErrorT tol)
Convert a tracking tolerance to a number of significant digits.
Definition num_traits.hpp:78
static double FromString(std::string const &s)
Parse a double from a string.
Definition num_traits.hpp:85
complex_dbl Complex
The complex companion type.
Definition num_traits.hpp:98
static unsigned NumDigits()
The number of significant digits (16 for double).
Definition num_traits.hpp:65
static double FromRational(mpq_rational const &n, unsigned)
Convert an exact rational to a double (precision ignored).
Definition num_traits.hpp:92
static mpq_rational FromString(std::string const &str)
Parse a decimal string to an exact mpq_rational.
Definition num_traits.hpp:400
static unsigned NumFuzzyDigits()
The number of digits to trust for fuzzy comparisons.
Definition num_traits.hpp:319
real_mp Real
The real companion type.
Definition num_traits.hpp:346
static real_mp FromString(std::string const &s)
Parse a multiprecision real from a string.
Definition num_traits.hpp:334
static unsigned TolToDigits(real_mp tol)
Convert a tracking tolerance to a number of significant digits.
Definition num_traits.hpp:326
static real_mp FromRational(mpq_rational const &n, unsigned precision)
Convert an exact rational to a multiprecision real at the given precision.
Definition num_traits.hpp:341
static unsigned NumDigits()
The number of significant digits (the current thread precision).
Definition num_traits.hpp:313
complex_mp Complex
The complex companion type.
Definition num_traits.hpp:347
Numeric traits for a bertini number type: digit counts, conversions, and companion types.
Definition num_traits.hpp:57