1 /* mpfr_print_binary -- print the internal binary representation of a
4 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
5 Contributed by the Arenaire and Caramel projects, INRIA.
7 This file is part of the GNU MPFR Library.
9 The GNU MPFR 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 MPFR 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 MPFR Library; see the file COPYING.LESSER. If not, see
21 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
22 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
24 #include "mpfr-impl.h"
27 mpfr_fprint_binary (FILE *stream, mpfr_srcptr x)
31 fprintf (stream, "@NaN@");
35 if (MPFR_SIGN (x) < 0)
36 fprintf (stream, "-");
39 fprintf (stream, "@Inf@");
40 else if (MPFR_IS_ZERO (x))
41 fprintf (stream, "0");
51 fprintf (stream, "0.");
52 for (n = (px - 1) / GMP_NUMB_BITS; ; n--)
56 MPFR_ASSERTN (n >= 0);
58 for (t = MPFR_LIMB_HIGHBIT; t != 0; t >>= 1)
60 putc ((wd & t) == 0 ? '0' : '1', stream);
65 ex = MPFR_GET_EXP (x);
66 MPFR_ASSERTN (ex >= LONG_MIN && ex <= LONG_MAX);
67 fprintf (stream, "E%ld", (long) ex);
76 mpfr_print_binary (mpfr_srcptr x)
78 mpfr_fprint_binary (stdout, x);
82 mpfr_print_mant_binary(const char *str, const mp_limb_t *p, mpfr_prec_t r)
85 mpfr_prec_t count = 0;
87 mp_size_t n = (r - 1) / GMP_NUMB_BITS + 1;
92 for(i = GMP_NUMB_BITS-1 ; i >=0 ; i--)
94 c = (p[n] & (((mp_limb_t)1L)<<i)) ? '1' : '0';
106 mpfr_dump_mant (const mp_limb_t *p, mpfr_prec_t r, mpfr_prec_t precx,
110 mpfr_prec_t count = 0;
112 mp_size_t n = (r - 1) / GMP_NUMB_BITS + 1;
114 for(n-- ; n>=0 ; n--)
116 for(i = GMP_NUMB_BITS-1 ; i >=0 ; i--)
118 c = (p[n] & (((mp_limb_t)1L)<<i)) ? '1' : '0';