/* mpfr_zeta -- Riemann Zeta function at a floating-point number Copyright 1999, 2000, 2001, 2002, 2003 Free Software Foundation. This file is part of the MPFR Library. The MPFR Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The MPFR Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the MPFR Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include "gmp.h" #include "mpfr.h" #include "gmp-impl.h" #include "longlong.h" int mpfr_zeta (mpfr_ptr result, mpfr_srcptr op, mp_rnd_t rnd_mode) { mpfr_t s,s2,x,y,u,b,v,nn,z,z2; int i, n, succes; int cmp1; if (MPFR_IS_NAN(op) || MPFR_SIGN(op) < 0) { MPFR_SET_NAN(result); MPFR_RET_NAN; } if (MPFR_IS_INF(op)) /* +infinity */ return mpfr_set_ui(result, 1, rnd_mode); cmp1 = mpfr_cmp_ui(op, 1); if (cmp1 < 0) { MPFR_SET_NAN(result); MPFR_RET_NAN; } if (cmp1 == 0) { MPFR_CLEAR_NAN(result); MPFR_SET_INF(result); MPFR_SET_POS(result); return 0; } /* 1 < op < +infinity */ /* first version */ if (mpfr_get_d1 (op) != 2.0 || rnd_mode != GMP_RNDN || MPFR_PREC(result) != 53) { fprintf(stderr, "not yet implemented\n"); exit(1); } mpfr_set_default_prec(67); mpfr_init(x); mpfr_init(y); mpfr_init(s); mpfr_init(s2); mpfr_init(u); mpfr_init(b); mpfr_init(v); mpfr_init(nn); mpfr_init(z); mpfr_init(z2); mpfr_set_ui(u,1,GMP_RNDN); mpfr_set_ui(s,0,GMP_RNDN); /* s=Somme des 1/i^2 (i=100...2) */ n=100; for (i=n; i>1; i--) { mpfr_div_ui(y,u,i*i,GMP_RNDN); mpfr_add(s,s,y,GMP_RNDN); } /* Application d'Euler-Maclaurin, jusqu'au terme 1/n^7 - n=100) */ /* mpfr_set_ui(nn,n,GMP_RNDN); */ mpfr_div_ui(z,u,n,GMP_RNDN); mpfr_mul(z2,z,z,GMP_RNDN); mpfr_div_2ui(v,z2,1,GMP_RNDN); mpfr_set(s2,z,GMP_RNDN); mpfr_sub(s2,s2,v,GMP_RNDN); mpfr_mul(z,z,z2,GMP_RNDN); mpfr_div_ui(v,z,6,GMP_RNDN); mpfr_add(s2,s2,v,GMP_RNDN); mpfr_mul(z,z,z2,GMP_RNDN); mpfr_div_ui(v,z,30,GMP_RNDN); mpfr_sub(s2,s2,v,GMP_RNDN); mpfr_mul(z,z,z2,GMP_RNDN); mpfr_div_ui(v,z,42,GMP_RNDN); mpfr_add(s2,s2,v,GMP_RNDN); mpfr_add(s,s,s2,GMP_RNDN); mpfr_add(s,s,u,GMP_RNDN); /*Peut-on arrondir ? La reponse est oui*/ succes=mpfr_can_round(s, 57, GMP_RNDN,GMP_RNDN, 53); if (succes) mpfr_set(result,s,GMP_RNDN); else { fprintf(stderr, "can't round in mpfr_zeta\n"); exit(1); } mpfr_clear(x); mpfr_clear(y); mpfr_clear(s); mpfr_clear(s2); mpfr_clear(u); mpfr_clear(b); mpfr_clear(v); mpfr_clear(nn); mpfr_clear(z); mpfr_clear(z2); return 1; /* result is inexact */ }