Actually hook powernow.4 into the build.
[dragonfly.git] / contrib / mpfr / print_raw.c
blob2038beed4a08e4eb1ecbb2c072d40ae951f4e974
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 Free Software Foundation, Inc.
5 Contributed by the Arenaire and Cacao 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 2.1 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.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
22 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 mp_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) / BITS_PER_MP_LIMB; ; 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 mp_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, mp_prec_t r)
84 int i;
85 mp_prec_t count = 0;
86 char c;
87 mp_size_t n = (r - 1) / BITS_PER_MP_LIMB + 1;
89 printf("%s ", str);
90 for(n-- ; n>=0 ; n--)
92 for(i = BITS_PER_MP_LIMB-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, mp_prec_t r, mp_prec_t precx,
107 mp_prec_t error)
109 int i;
110 mp_prec_t count = 0;
111 char c;
112 mp_size_t n = (r - 1) / BITS_PER_MP_LIMB + 1;
114 for(n-- ; n>=0 ; n--)
116 for(i = BITS_PER_MP_LIMB-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');