13 void to_int(mpz_t intRep, mpfr_t a) {
26 int limbs =
std::ceil(
double(a->_mpfr_prec)/
double(mp_bits_per_limb));
43 unsigned offset = mp_bits_per_limb - (a->_mpfr_prec % mp_bits_per_limb);
50 mpz_set_ui(tmp, a->_mpfr_d[limbs-1]);
52 mpz_mul_2exp(tmp, tmp, (mp_bits_per_limb*(limbs-1)));
53 mpz_add(mant, mant, tmp);
57 mpz_cdiv_q_2exp(mant, mant, offset);
64 mpz_set_ui(tmp, (a->_mpfr_exp +
std::abs(mpfr_get_emin())));
66 mpz_mul_2exp(tmp,tmp,a->_mpfr_prec);
69 mpz_add(mant,mant,tmp);
70 mpz_mul_si(mant,mant,a->_mpfr_sign);
71 mpz_set(intRep, mant);
84 unsigned distance(mpfr_t a, mpfr_t b) {
94 long offset = a->_mpfr_exp - b->_mpfr_exp;
100 mpz_abs(intRepA, intRepA);
101 mpz_abs(intRepB, intRepB);
106 if(mpfr_zero_p(a) != 0) {
107 if(mpfr_zero_p(b) != 0){
117 mpfr_init2(
zero,mpfr_get_prec(a));
118 mpz_init(intRepZero);
120 mpfr_set_ui(
zero,0, MPFR_RNDZ);
121 if(b->_mpfr_sign > 0) {
122 mpfr_nextabove(
zero);
124 mpfr_nextbelow(
zero);
128 mpz_abs(intRepZero, intRepZero);
129 mpz_sub(distance, intRepB,intRepZero);
130 mpz_add_ui(distance,distance, 1);
133 mpz_clear(intRepZero);
134 }
else if(mpfr_zero_p(b) != 0) {
137 mpfr_init2(
zero,mpfr_get_prec(a));
138 mpz_init(intRepZero);
140 mpfr_set_ui(
zero,0, MPFR_RNDZ);
141 if(a->_mpfr_sign > 0) {
142 mpfr_nextabove(
zero);
144 mpfr_nextbelow(
zero);
149 mpz_abs(intRepZero, intRepZero);
150 mpz_sub(distance, intRepA,intRepZero);
151 mpz_add_ui(distance,distance, 1);
154 mpz_clear(intRepZero);
155 }
else if(a->_mpfr_sign == b->_mpfr_sign) {
156 mpz_sub(distance, intRepA, intRepB);
157 mpz_abs(distance,distance);
160 mpfr_init2(zeroA,mpfr_get_prec(a));
162 mpfr_init2(zeroB,mpfr_get_prec(a));
164 mpfr_set_ui(zeroA,0, MPFR_RNDZ);
165 mpfr_set_ui(zeroB,0, MPFR_RNDZ);
167 if(a->_mpfr_sign > 0) {
168 mpfr_nextabove(zeroA);
169 mpfr_nextbelow(zeroB);
171 mpfr_nextbelow(zeroA);
172 mpfr_nextabove(zeroB);
175 mpz_init(intRepZeroA);
177 mpz_init(intRepZeroB);
181 to_int(intRepZeroA, zeroA);
182 mpz_abs(intRepZeroA, intRepZeroA);
183 to_int(intRepZeroB, zeroB);
184 mpz_abs(intRepZeroB, intRepZeroB);
186 mpz_sub(distance, intRepA,intRepZeroA);
187 mpz_sub(d2, intRepB,intRepZeroB);
188 mpz_add(distance, distance, d2);
189 mpz_add_ui(distance,distance, 2);
193 mpz_clear(intRepZeroA);
194 mpz_clear(intRepZeroB);
200 unsigned result = mpz_get_ui(distance) - 2*
std::abs(offset)*a->_mpfr_prec;
210 int main (
int argc,
char** argv)
212 #ifdef USE_MPFR_FLOAT
216 std::string fString =
"%." + std::to_string(eps.
precision()+5) +
"RNf";
218 char* format = (
char*)fString.c_str();
219 std::cout <<
"Precision is " << eps.
precision() << std::endl;
220 mpfr_sprintf(out,
"%.RDe", eps.
value());
221 std::cout << std::string(out) << std::endl;
int main(int argc, char **argv)
Interval< Number > ceil(const Interval< Number > &_in)
Method which returns the next larger integer of the passed number or the number itself,...
Interval< Number > abs(const Interval< Number > &_in)
Method which returns the absolute value of the passed number.
Integer to_int(const Interval< Number > &_floatInterval)
Casts the Interval to an arbitrary integer type which has a constructor for a native int.
auto zero()
Return a zero duration.
Templated wrapper class which allows universal usage of different IEEE 754 implementations.
precision_t precision() const
If precision is used, this getter returns the acutal precision (default: 53 bit).
const FloatType & value() const
Getter for the raw value contained.