Annotation of OpenXM_contrib/gmp/mpfr/out_str.c, Revision 1.1.1.1
1.1 maekawa 1: /* mpfr_out_str -- output a floating-point number to a stream
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 "mpfr.h"
27:
28: size_t
29: #if __STDC__
30: mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op,
31: unsigned char rnd_mode)
32: #else
33: mpfr_out_str (stream, base, n_digits, op, rnd_mode)
34: FILE *stream;
35: int base;
36: size_t n_digits;
37: mpfr_srcptr op;
38: unsigned char rnd_mode;
39: #endif
40: {
41: char *s,*s0; size_t l; mp_exp_t e;
42:
43: if (FLAG_NAN(op)) { fprintf(stream, "NaN"); return 3; }
44: if (!NOTZERO(op)) { fprintf(stream, "0"); return 1; }
45:
46: s = mpfr_get_str(NULL, &e, base, n_digits, op, rnd_mode);
47: s0 = s;
48: /* for op=3.1416 we have s = "31416" and e = 1 */
49:
50: l = strlen(s)+1;
51: if (*s == '-') fputc(*s++, stream);
52:
53: fputc(*s++, stream); e--; /* writes leading digit */
54: fputc('.', stream); /* decimal point */
55: fputs(s, stream); /* rest of mantissa */
56: if (e) {
57: fputc((base>10) ? '@' : 'e', stream); l++;
58: sprintf(s, "%ld", e);
59: l += strlen(s);
60: fprintf(stream, "%s", s);
61: }
62:
63: (*_mp_free_func)(s0, l);
64: return l;
65: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>