Annotation of OpenXM_contrib/gmp/mpfr/out_str.c, Revision 1.1.1.2
1.1 maekawa 1: /* mpfr_out_str -- output a floating-point number to a stream
2:
1.1.1.2 ! ohara 3: Copyright 1999, 2001 Free Software Foundation, Inc.
1.1 maekawa 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
1.1.1.2 ! ohara 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
1.1 maekawa 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
1.1.1.2 ! ohara 14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1.1 maekawa 15: License for more details.
16:
1.1.1.2 ! ohara 17: You should have received a copy of the GNU Lesser General Public License
1.1 maekawa 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>
1.1.1.2 ! ohara 23: #include <string.h>
! 24: #include <limits.h>
1.1 maekawa 25: #include "gmp.h"
26: #include "gmp-impl.h"
27: #include "mpfr.h"
1.1.1.2 ! ohara 28: #include "mpfr-impl.h"
1.1 maekawa 29:
30: size_t
31: mpfr_out_str (FILE *stream, int base, size_t n_digits, mpfr_srcptr op,
1.1.1.2 ! ohara 32: mp_rnd_t rnd_mode)
1.1 maekawa 33: {
1.1.1.2 ! ohara 34: char *s, *s0;
! 35: size_t l;
! 36: mp_exp_t e;
! 37:
! 38: if (MPFR_IS_NAN(op))
! 39: {
! 40: fprintf (stream, "NaN");
! 41: return 3;
! 42: }
! 43:
! 44: if (MPFR_IS_INF(op))
! 45: {
! 46: if (MPFR_SIGN(op) > 0)
! 47: {
! 48: fprintf (stream, "Inf");
! 49: return 3;
! 50: }
! 51: else
! 52: {
! 53: fprintf (stream, "-Inf");
! 54: return 4;
! 55: }
! 56: }
! 57:
! 58: if (MPFR_IS_ZERO(op))
! 59: {
! 60: if (MPFR_SIGN(op) > 0)
! 61: {
! 62: fprintf(stream, "0");
! 63: return 1;
! 64: }
! 65: else
! 66: {
! 67: fprintf(stream, "-0");
! 68: return 2;
! 69: }
! 70: }
1.1 maekawa 71:
1.1.1.2 ! ohara 72: s = mpfr_get_str (NULL, &e, base, n_digits, op, rnd_mode);
1.1 maekawa 73:
74: s0 = s;
75: /* for op=3.1416 we have s = "31416" and e = 1 */
76:
1.1.1.2 ! ohara 77: l = strlen (s) + 1; /* size of allocated block returned by mpfr_get_str
! 78: - may be incorrect, as only an upper bound? */
! 79: if (*s == '-')
! 80: fputc (*s++, stream);
! 81:
! 82: /* outputs mantissa */
! 83: fputc (*s++, stream); e--; /* leading digit */
! 84: fputc ('.', stream); /* decimal point */
! 85: fputs (s, stream); /* rest of mantissa */
! 86: (*__gmp_free_func) (s0, l);
! 87:
! 88: /* outputs exponent */
! 89: if (e)
! 90: {
! 91: MPFR_ASSERTN(e >= LONG_MIN);
! 92: MPFR_ASSERTN(e <= LONG_MAX);
! 93: l += fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), (long) e);
! 94: }
! 95:
1.1 maekawa 96: return l;
97: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>