static void check_overflow () { mpfr_t max; mpfi_t a; mpfr_t b; int inexact; mpfi_init2 (a, 53); mpfr_init2 (max, 53); mpfr_init2 (b, 53); mpfr_set_ui (&(a->left), 1, MPFI_RNDD); mpfr_set_inf (max, +1); mpfr_nextbelow (max); mpfr_set (&(a->right), max, MPFI_RNDU); mpfr_set_ui (b, +1, MPFI_RNDD); inexact = mpfi_add_fr (a, a, b); if (!mpfr_inf_p (&(a->right))) { printf ("Error: mpfi_add_fr does not correctly handle positive " "overflow.\n"); exit (1); } if (!MPFI_RIGHT_IS_INEXACT (inexact)) { printf ("Error: mpfi_add_fr does not return correct value when positive " "overflow.\n"); exit (1); } mpfr_set_inf (max, -1); mpfr_nextabove (max); mpfr_set (&(a->left), max, MPFI_RNDD); mpfr_set_ui (&(a->right), 1, MPFI_RNDU); mpfr_set_si (b, -1, MPFI_RNDD); inexact = mpfi_add_fr (a, a, b); if (!mpfr_inf_p (&(a->left))) { printf ("Error: mpfi_add_fr does not correctly handle negative " "overflow.\n"); exit (1); } if (!MPFI_LEFT_IS_INEXACT (inexact)) { printf ("Error: mpfi_add_fr does not return correct value when negative " "overflow.\n"); exit (1); } mpfi_clear (a); mpfr_clear (b); mpfr_clear (max); }
/* This function computes an interval bound for a polynomial in cheb basis. by using Clenshaw's method -- The n coefficients are given in coeffs.*/ void evaluateChebPolynomialClenshaw(sollya_mpfi_t bound, int n, sollya_mpfi_t *coeffs, mpfi_t x,mpfi_t x0){ int i; sollya_mpfi_t z, zz, z1,b0,b1; mpfr_t a, b; mp_prec_t prec; prec = sollya_mpfi_get_prec(bound); sollya_mpfi_init2(z, prec); sollya_mpfi_init2(zz, prec); sollya_mpfi_init2(z1, prec); sollya_mpfi_init2(b0, prec); sollya_mpfi_init2(b1, prec); mpfr_init2(a, prec); mpfr_init2(b, prec); sollya_mpfi_get_right(b,x); sollya_mpfi_get_left(a,x); sollya_mpfi_set_fr(z1,b); sollya_mpfi_sub_fr(z1,z1,a); sollya_mpfi_inv(z1,z1); sollya_mpfi_mul_ui(z,z1,2); /*z=2/(b-a)*/ sollya_mpfi_set_fr(zz,b); mpfi_add_fr(zz,zz,a); sollya_mpfi_mul(zz,zz,z1); /*zz=(b+a)/(b-a)*/ sollya_mpfi_mul(z,z,x0); sollya_mpfi_sub(z,z,zz); /*z=2/(b-a) * x0 - (b+a)/(b-a)*/ /*Do the clenshaw algo*/ /*b1:=[0.,0.]; b0:=[0.,0.]; for i from n to 2 by -1 do bb:=(((2&*z)&*b0) &-b1) &+L[i]; b1:=b0; b0:=bb; end do; bb:=((z&*b0) &-b1) &+L[1]; return bb; */ sollya_mpfi_set_ui(b0,0); sollya_mpfi_set_ui(b1,0); for(i=n-1;i>0; i--){ sollya_mpfi_mul(zz,z,b0); sollya_mpfi_mul_ui(zz,zz,2); sollya_mpfi_sub(zz,zz,b1); sollya_mpfi_add(zz,zz,coeffs[i]); sollya_mpfi_set(b1,b0); sollya_mpfi_set(b0,zz); } sollya_mpfi_mul(zz,z,b0); sollya_mpfi_sub(zz,zz,b1); sollya_mpfi_add(zz,zz,coeffs[0]); sollya_mpfi_set(bound, zz); sollya_mpfi_clear(zz); sollya_mpfi_clear(z); sollya_mpfi_clear(z1); sollya_mpfi_clear(b0); sollya_mpfi_clear(b1); mpfr_clear(b); mpfr_clear(a); }