fixed odd read('*a') behaviour in Windows (A. Kakuto)
[luatex.git] / source / libs / mpfr / mpfr-3.1.2 / src / print_raw.c
blob08b7baf5d7430ffbaed065fb9f6a8464691973e7
1 /* mpfr_print_binary -- print the internal binary representation of a
2 floating-point number
4 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
5 Contributed by the AriC 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"
26 void
27 mpfr_fprint_binary (FILE *stream, mpfr_srcptr x)
29 if (MPFR_IS_NAN (x))
31 fprintf (stream, "@NaN@");
32 return;
35 if (MPFR_SIGN (x) < 0)
36 fprintf (stream, "-");
38 if (MPFR_IS_INF (x))
39 fprintf (stream, "@Inf@");
40 else if (MPFR_IS_ZERO (x))
41 fprintf (stream, "0");
42 else
44 mp_limb_t *mx;
45 mpfr_prec_t px;
46 mp_size_t n;
48 mx = MPFR_MANT (x);
49 px = MPFR_PREC (x);
51 fprintf (stream, "0.");
52 for (n = (px - 1) / GMP_NUMB_BITS; ; n--)
54 mp_limb_t wd, t;
56 MPFR_ASSERTN (n >= 0);
57 wd = mx[n];
58 for (t = MPFR_LIMB_HIGHBIT; t != 0; t >>= 1)
60 putc ((wd & t) == 0 ? '0' : '1', stream);
61 if (--px == 0)
63 mpfr_exp_t ex;
65 ex = MPFR_GET_EXP (x);
66 MPFR_ASSERTN (ex >= LONG_MIN && ex <= LONG_MAX);
67 fprintf (stream, "E%ld", (long) ex);
68 return;
75 void
76 mpfr_print_binary (mpfr_srcptr x)
78 mpfr_fprint_binary (stdout, x);
81 void
82 mpfr_print_mant_binary(const char *str, const mp_limb_t *p, mpfr_prec_t r)
84 int i;
85 mpfr_prec_t count = 0;
86 char c;
87 mp_size_t n = MPFR_PREC2LIMBS (r);
89 printf("%s ", str);
90 for(n-- ; n>=0 ; n--)
92 for(i = GMP_NUMB_BITS-1 ; i >=0 ; i--)
94 c = (p[n] & (((mp_limb_t)1L)<<i)) ? '1' : '0';
95 putchar(c);
96 count++;
97 if (count == r)
98 putchar('[');
100 putchar('.');
102 putchar('\n');
105 void
106 mpfr_dump_mant (const mp_limb_t *p, mpfr_prec_t r, mpfr_prec_t precx,
107 mpfr_prec_t error)
109 int i;
110 mpfr_prec_t count = 0;
111 char c;
112 mp_size_t n = MPFR_PREC2LIMBS (r);
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';
119 putchar(c);
120 count++;
121 if (count == precx)
122 putchar (',');
123 if (count == error)
124 putchar('[');
126 putchar('.');
128 putchar('\n');