1 /* mpf_out_str (stream, base, n_digits, op) -- Print N_DIGITS digits from
2 the float OP to STREAM in base BASE. Return the number of characters
3 written, or 0 if an error occurred.
5 Copyright 1996, 1997, 2001, 2002, 2005 Free Software Foundation, Inc.
7 This file is part of the GNU MP Library.
9 The GNU MP Library is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
14 The GNU MP Library is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
22 #define _GNU_SOURCE /* for DECIMAL_POINT in langinfo.h */
30 #include <langinfo.h> /* for nl_langinfo */
34 #include <locale.h> /* for localeconv */
42 mpf_out_str (FILE *stream, int base, size_t n_digits, mpf_srcptr op)
54 MPF_SIGNIFICANT_DIGITS (n_digits, base, op->_mp_prec);
59 /* Consider these changes:
60 * Don't allocate memory here for huge n_digits; pass NULL to mpf_get_str.
61 * Make mpf_get_str allocate extra space when passed NULL, to avoid
62 allocating two huge string buffers.
63 * Implement more/other allocation reductions tricks. */
65 str = (char *) TMP_ALLOC (n_digits + 2); /* extra for minus sign and \0 */
67 mpf_get_str (str, &exp, base, n_digits, op);
68 n_digits = strlen (str);
82 const char *point = GMP_DECIMAL_POINT;
83 size_t pointlen = strlen (point);
85 fwrite (point, 1, pointlen, stream);
86 written += pointlen + 1;
92 fwret = fwrite (str, 1, n_digits, stream);
99 fpret = fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), exp);
104 return ferror (stream) ? 0 : written;