1
/* mpfr_out_str -- output a floating-point number to a stream
3
Copyright 1999, 2001, 2003 Free Software Foundation, Inc.
5
This file is part of the MPFR Library.
7
The MPFR Library is free software; you can redistribute it and/or modify
8
it under the terms of the GNU Lesser General Public License as published by
9
the Free Software Foundation; either version 2.1 of the License, or (at your
10
option) any later version.
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 Lesser General Public
15
License for more details.
17
You should have received a copy of the GNU Lesser 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. */
28
#include "mpfr-impl.h"
31
mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op,
38
/* when stream=NULL, output to stdout */
44
fprintf (stream, "NaN");
50
if (MPFR_SIGN(op) > 0)
52
fprintf (stream, "Inf");
57
fprintf (stream, "-Inf");
64
if (MPFR_SIGN(op) > 0)
71
fprintf(stream, "-0");
76
s = mpfr_get_str (NULL, &e, base, n_digits, op, rnd_mode);
79
/* for op=3.1416 we have s = "31416" and e = 1 */
81
l = strlen (s) + 1; /* size of allocated block returned by mpfr_get_str
82
- may be incorrect, as only an upper bound? */
86
/* outputs mantissa */
87
fputc (*s++, stream); e--; /* leading digit */
88
fputc ('.', stream); /* decimal point */
89
fputs (s, stream); /* rest of mantissa */
90
(*__gmp_free_func) (s0, l);
92
/* outputs exponent */
95
MPFR_ASSERTN(e >= LONG_MIN);
96
MPFR_ASSERTN(e <= LONG_MAX);
97
l += fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), (long) e);