[BACK]Return to out_str.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpf

Annotation of OpenXM_contrib/gmp/mpf/out_str.c, Revision 1.1.1.2

1.1       maekawa     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.
                      4:
1.1.1.2 ! maekawa     5: Copyright (C) 1996, 1997 Free Software Foundation, Inc.
1.1       maekawa     6:
                      7: This file is part of the GNU MP Library.
                      8:
                      9: The GNU MP Library is free software; you can redistribute it and/or modify
1.1.1.2 ! maekawa    10: it under the terms of the GNU Lesser General Public License as published by
        !            11: the Free Software Foundation; either version 2.1 of the License, or (at your
1.1       maekawa    12: option) any later version.
                     13:
                     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
1.1.1.2 ! maekawa    16: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
1.1       maekawa    17: License for more details.
                     18:
1.1.1.2 ! maekawa    19: You should have received a copy of the GNU Lesser General Public License
1.1       maekawa    20: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                     21: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     22: MA 02111-1307, USA. */
                     23:
                     24: #include <stdio.h>
1.1.1.2 ! maekawa    25: #include <string.h>
1.1       maekawa    26: #include "gmp.h"
                     27: #include "gmp-impl.h"
                     28:
                     29: size_t
                     30: #if __STDC__
                     31: mpf_out_str (FILE *stream, int base, size_t n_digits, mpf_srcptr op)
                     32: #else
                     33: mpf_out_str (stream, base, n_digits, op)
                     34:      FILE *stream;
                     35:      int base;
                     36:      size_t n_digits;
                     37:      mpf_srcptr op;
                     38: #endif
                     39: {
                     40:   char *str;
                     41:   mp_exp_t exp;
                     42:   size_t written;
                     43:   TMP_DECL (marker);
                     44:
                     45:   TMP_MARK (marker);
                     46:
                     47:   if (base == 0)
                     48:     base = 10;
                     49:   if (n_digits == 0)
                     50:     n_digits = (((op->_mp_prec - 1) * BITS_PER_MP_LIMB)
                     51:                * __mp_bases[base].chars_per_bit_exactly);
                     52:
                     53:   if (stream == 0)
                     54:     stream = stdout;
                     55:
                     56:   str = (char *) TMP_ALLOC (n_digits + 2); /* extra for minus sign and \0 */
                     57:
                     58:   mpf_get_str (str, &exp, base, n_digits, op);
                     59:   n_digits = strlen (str);
                     60:
                     61:   written = 0;
                     62:
                     63:   /* Write sign */
                     64:   if (str[0] == '-')
                     65:     {
                     66:       str++;
                     67:       fputc ('-', stream);
                     68:       written = 1;
1.1.1.2 ! maekawa    69:       n_digits--;
1.1       maekawa    70:     }
                     71:
                     72:   fwrite ("0.", 1, 2, stream);
                     73:   written += 2;
                     74:
                     75:   /* Write mantissa */
                     76:   {
                     77:     size_t fwret;
                     78:     fwret = fwrite (str, 1, n_digits, stream);
                     79:     written += fwret;
                     80:   }
                     81:
                     82:   /* Write exponent */
                     83:   {
                     84:     int fpret;
                     85:     fpret = fprintf (stream, (base <= 10 ? "e%ld" : "@%ld"), exp);
                     86:     written += fpret;
                     87:   }
                     88:
                     89:   TMP_FREE (marker);
                     90:   return ferror (stream) ? 0 : written;
                     91: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>