Here are results using MPFR-3.0.0-p8 with GMP-4.3.2 with precision = 80
It is about 20 times longer than gcc and long double.
n = 1 distance = 5.0000000000e-01 LI = 3 log2(LI) = 2; time = 0 seconds
n = 2 distance = 2.5000000000e-01 LI = 5 log2(LI) = 2; time = 0 seconds
n = 3 distance = 1.2500000000e-01 LI = 10 log2(LI) = 3; time = 0 seconds
n = 4 distance = 6.2500000000e-02 LI = 19 log2(LI) = 4; time = 0 seconds
n = 5 distance = 3.1250000000e-02 LI = 35 log2(LI) = 5; time = 0 seconds
n = 6 distance = 1.5625000000e-02 LI = 68 log2(LI) = 6; time = 0 seconds
n = 7 distance = 7.8125000000e-03 LI = 133 log2(LI) = 7; time = 0 seconds
n = 8 distance = 3.9062500000e-03 LI = 261 log2(LI) = 8; time = 0 seconds
n = 9 distance = 1.9531250000e-03 LI = 518 log2(LI) = 9; time = 0 seconds
n = 10 distance = 9.7656250000e-04 LI = 1031 log2(LI) = 10; time = 0 seconds
n = 11 distance = 4.8828125000e-04 LI = 2055 log2(LI) = 11; time = 0 seconds
n = 12 distance = 2.4414062500e-04 LI = 4104 log2(LI) = 12; time = 0 seconds
n = 13 distance = 1.2207031250e-04 LI = 8201 log2(LI) = 13; time = 0 seconds
n = 14 distance = 6.1035156250e-05 LI = 16394 log2(LI) = 14; time = 0 seconds
n = 15 distance = 3.0517578125e-05 LI = 32778 log2(LI) = 15; time = 0 seconds
n = 16 distance = 1.5258789062e-05 LI = 65547 log2(LI) = 16; time = 0 seconds
n = 17 distance = 7.6293945312e-06 LI = 131084 log2(LI) = 17; time = 0 seconds
n = 18 distance = 3.8146972656e-06 LI = 262156 log2(LI) = 18; time = 0 seconds
n = 19 distance = 1.9073486328e-06 LI = 524301 log2(LI) = 19; time = 0 seconds
n = 20 distance = 9.5367431641e-07 LI = 1048590 log2(LI) = 20; time = 1 seconds
n = 21 distance = 4.7683715820e-07 LI = 2097166 log2(LI) = 21; time = 0 seconds
n = 22 distance = 2.3841857910e-07 LI = 4194319 log2(LI) = 22; time = 1 seconds
n = 23 distance = 1.1920928955e-07 LI = 8388624 log2(LI) = 23; time = 3 seconds
n = 24 distance = 5.9604644775e-08 LI = 16777232 log2(LI) = 24; time = 4 seconds
n = 25 distance = 2.9802322388e-08 LI = 33554449 log2(LI) = 25; time = 10 seconds
n = 26 distance = 1.4901161194e-08 LI = 67108882 log2(LI) = 26; time = 20 seconds
n = 27 distance = 7.4505805969e-09 LI = 134217747 log2(LI) = 27; time = 39 seconds
n = 28 distance = 3.7252902985e-09 LI = 268435476 log2(LI) = 28; time = 78 seconds
n = 29 distance = 1.8626451492e-09 LI = 536870933 log2(LI) = 29; time = 152 seconds
n = 30 distance = 9.3132257462e-10 LI = 1073741846 log2(LI) = 30; time = 298 seconds
n = 31 distance = 4.6566128731e-10 LI = 2147483671 log2(LI) = 31; time = 596 seconds
n = 32 distance = 2.3283064365e-10 LI = 4294967320 log2(LI) = 32; time = 1206 seconds
To compile :
gcc -lm -lmpfr -lgmp -Wall -O2 pmpfr.c
#include <stdio.h>
#include <math.h> // log2
#include <gmp.h>
#include <mpfr.h>
#include <time.h>
// MPFR general settings
mpfr_prec_t precision = 80; // the number of bits used to represent the significand of a floating-point number
mpfr_rnd_t RoundMode = MPFR_RNDD; // the way to round the result of a floating-point operation, round toward minus infinity (roundTowardNegative in IEEE 754-2008),
double GiveLastIteration_mpfr(
mpfr_t zx,
mpfr_t zy,
mpfr_t cx,
mpfr_t cy,
mpfr_t ER2)
{
double i=0.0;
mpfr_t temp;
mpfr_t zx2; // zx^2
mpfr_t zy2; // zy^2
// initializes MPFR variables with default_prec
mpfr_inits(temp, zx2, zy2, (mpfr_ptr) 0 );
mpfr_mul( zy2, zy, zy, GMP_RNDN); /* zy2 = zy * zy; */
mpfr_mul( zx2, zx, zx, GMP_RNDN); /* zx2 = zx * zx; */
mpfr_add( temp, zx2, zy2, GMP_RNDN); // temp = zx2 + zy2
while (mpfr_greater_p(ER2, temp)) // while (Zx2+Zy2<ER2
{
/* zy = 2.0*zx*zy + cy; */
mpfr_mul( temp, zx, zy, GMP_RNDN); // temp = zx*zy
mpfr_mul_ui(temp, temp, 2.0, GMP_RNDN); // temp = 2 * temp = 2*zx*zy
mpfr_add( zy, temp, cy, GMP_RNDN);
/* zx = zx^2 - zy^2 + cx; */
mpfr_sub( temp, zx2, zy2, GMP_RNDN); // temp = zx^2 - zy^2
mpfr_add( zx, temp, cx, GMP_RNDN); // temp = temp + cx
//
mpfr_mul( zy2, zy, zy, GMP_RNDN); /* zy2 = zy * zy; */
mpfr_mul( zx2, zx, zx, GMP_RNDN); /* zx2 = zx * zx; */
mpfr_add( temp, zx2, zy2, GMP_RNDN); // temp = zx2 + zy2
i+=1.0;
}
mpfr_clears (temp, zx2, zy2, (mpfr_ptr) 0 );
return i;
}
int main (void)
{
// declares variables
double LastIteration;
time_t start,end;
double dif;
int n;
mpfr_t zpx, zpy; // parabolic fixed point zp = zpx + zpy*I = 0.5 for c=1/4
mpfr_t zx, zy; // point z = zx + zy*I
mpfr_t distance; // between zp and z
mpfr_t cx, cy; // point c = cx + cy*
mpfr_t base, exponent;
mpfr_t ER ; // Escape Radius ; it defines target set = { z: abs(z)>ER}; all points z in the target set are escaping to infinity
mpfr_t ER2; // ER2= ER * ER
mpfr_t t;
mpfr_set_default_prec(precision);
// initializes MPFR variables with default_prec
mpfr_inits(ER, ER2, zpx, zpy, zx, zy, distance, cx, cy, base, exponent, t, (mpfr_ptr) 0 );
// Assignment Functions
mpfr_set_ld (zpx, 0.5, RoundMode);
mpfr_set_ld (zpy, 0.0, RoundMode);
mpfr_set_ld (zy, 0.0, RoundMode);
mpfr_set_ld (cx, 0.25, RoundMode);
mpfr_set_ld (cy, 0.0, RoundMode);
mpfr_set_ld (base, 2.0, RoundMode);
mpfr_set_ld (ER, 2.0, RoundMode);
mpfr_set_ld (t, -1.0, RoundMode);
// computations
mpfr_mul(ER2, ER, ER, GMP_RNDN); //
for (n = 1; n <= 100; n++)
{
time (&start);
mpfr_pow_si(distance,base, - n, RoundMode);
mpfr_add(zx, zpx, distance, RoundMode);
LastIteration = GiveLastIteration_mpfr(zx, zy, cx, cy, ER2);
time (&end);
dif = difftime(end,start);
mpfr_printf ("n = %3d distance = %.10Re LI = %10.0f log2(LI) = %3.0f; time = %2.0f seconds \n", n, distance, LastIteration, log2(LastIteration), dif);
}
printf ("Using MPFR-%s with GMP-%s with precision = %u bits \n", mpfr_version, gmp_version, (unsigned int) precision);
// free the space used by the MPFR variables
mpfr_clears (ER, ER2, zpx, zpy, zx, zy, distance, cx, cy, base, exponent, (mpfr_ptr) 0);
mpfr_free_cache (); /* free the cache for constants like pi */
return 0;
}