Annotation of OpenXM_contrib/gmp/mpfr/zeta.c, Revision 1.1
1.1 ! maekawa 1: /* mpfr_zeta -- Riemann Zeta function at a floating-point number
! 2:
! 3: Copyright (C) 1999 PolKA project, Inria Lorraine and Loria
! 4:
! 5: This file is part of the MPFR Library.
! 6:
! 7: The MPFR Library is free software; you can redistribute it and/or modify
! 8: it under the terms of the GNU Library General Public License as published by
! 9: the Free Software Foundation; either version 2 of the License, or (at your
! 10: option) any later version.
! 11:
! 12: The MPFR Library is distributed in the hope that it will be useful, but
! 13: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
! 15: License for more details.
! 16:
! 17: You should have received a copy of the GNU Library General Public License
! 18: along with the MPFR Library; see the file COPYING.LIB. If not, write to
! 19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
! 20: MA 02111-1307, USA. */
! 21:
! 22: #include <stdio.h>
! 23: #include <math.h>
! 24: #include "gmp.h"
! 25: #include "gmp-impl.h"
! 26: #include "longlong.h"
! 27: #include "mpfr.h"
! 28:
! 29: int
! 30: #if __STDC__
! 31: mpfr_zeta(mpfr_ptr result, mpfr_srcptr op, unsigned char rnd_mode)
! 32: #else
! 33: mpfr_zeta(result, op, rnd_mode)
! 34: mpfr_ptr result;
! 35: mpfr_srcptr op;
! 36: unsigned char rnd_mode;
! 37: #endif
! 38: {
! 39: mpfr_t s,s2,x,y,u,b,v,nn,z,z2;
! 40: int i,n,succes;
! 41:
! 42: /* first version */
! 43: if (mpfr_get_d(op) != 2.0 || rnd_mode != GMP_RNDN
! 44: || PREC(result) != 53) {
! 45: fprintf(stderr, "not yet implemented\n"); exit(1);
! 46: }
! 47:
! 48: mpfr_set_default_prec(67);
! 49: mpfr_init(x);
! 50: mpfr_init(y);
! 51: mpfr_init(s);
! 52: mpfr_init(s2);
! 53: mpfr_init(u);
! 54: mpfr_init(b);
! 55: mpfr_init(v);
! 56: mpfr_init(nn);
! 57: mpfr_init(z);
! 58: mpfr_init(z2);
! 59: mpfr_set_ui(u,1,GMP_RNDN);
! 60: mpfr_set_ui(s,0,GMP_RNDN);
! 61: /*s=Somme des 1/i^2 (i=100...2)*/
! 62: n=100;
! 63: for (i=n; i>1; i--)
! 64: {
! 65: mpfr_set_ui(x,i*i,GMP_RNDN);
! 66: mpfr_div(y,u,x,GMP_RNDN);
! 67: mpfr_add(s,s,y,GMP_RNDN);
! 68: };
! 69: /*mpfr_print_raw(s);printf("\n");
! 70: t=mpfr_out_str(stdout,10,0,s,GMP_RNDN);printf("\n");*/
! 71: /*Application d'Euler-Maclaurin, jusqu'au terme 1/n^7 - n=100)*/
! 72: mpfr_set_ui(nn,n,GMP_RNDN);
! 73: mpfr_div(z,u,nn,GMP_RNDN);
! 74: mpfr_set(s2,z,GMP_RNDN);
! 75: mpfr_mul(z2,z,z,GMP_RNDN);
! 76: mpfr_div_2exp(v,z2,1,GMP_RNDN);
! 77: mpfr_sub(s2,s2,v,GMP_RNDN);
! 78: mpfr_set_ui(b,6,GMP_RNDN);
! 79: mpfr_mul(z,z,z2,GMP_RNDN);
! 80: mpfr_div(v,z,b,GMP_RNDN);
! 81: mpfr_add(s2,s2,v,GMP_RNDN);
! 82: mpfr_set_si(b,-30,GMP_RNDN);
! 83: mpfr_mul(z,z,z2,GMP_RNDN);
! 84: mpfr_div(v,z,b,GMP_RNDN);
! 85: mpfr_add(s2,s2,v,GMP_RNDN);
! 86: mpfr_set_si(b,42,GMP_RNDN);
! 87: mpfr_mul(z,z,z2,GMP_RNDN);
! 88: mpfr_div(v,z,b,GMP_RNDN);
! 89: mpfr_add(s2,s2,v,GMP_RNDN);
! 90: /*mpfr_print_raw(s2);printf("\n");
! 91: t=mpfr_out_str(stdout,10,0,s2,GMP_RNDN);printf("\n");*/
! 92: mpfr_add(s,s,s2,GMP_RNDN);
! 93: /*mpfr_print_raw(s);printf("\n");
! 94: t=mpfr_out_str(stdout,10,0,s,GMP_RNDN);printf("\n");*/
! 95: mpfr_add(s,s,u,GMP_RNDN);
! 96: /*mpfr_print_raw(s);printf("\n");
! 97: t=mpfr_out_str(stdout,10,0,s,GMP_RNDN);printf("\n");*/
! 98: /*Peut-on arrondir ? La reponse est oui*/
! 99: succes=mpfr_can_round(s,57,GMP_RNDN,GMP_RNDN,53);
! 100: if (succes) mpfr_set(result,s,GMP_RNDN);
! 101: else {
! 102: fprintf(stderr, "can't round in mpfr_zeta\n"); exit(1);
! 103: }
! 104:
! 105: mpfr_clear(x);
! 106: mpfr_clear(y);
! 107: mpfr_clear(s);
! 108: mpfr_clear(s2);
! 109: mpfr_clear(u);
! 110: mpfr_clear(b);
! 111: mpfr_clear(v);
! 112: mpfr_clear(nn);
! 113: mpfr_clear(z);
! 114: mpfr_clear(z2);
! 115: return 1; /* result is inexact */
! 116: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>