Annotation of OpenXM_contrib/gmp/mpfr/print_raw.c, Revision 1.1.1.1
1.1 maekawa 1: /* mpfr_print_raw -- print the internal binary representation of a
2: floating-point number
3:
4: Copyright (C) 1999 PolKA project, Inria Lorraine and Loria
5:
6: This file is part of the MPFR Library.
7:
8: The MPFR Library is free software; you can redistribute it and/or modify
9: it under the terms of the GNU Library General Public License as published by
10: the Free Software Foundation; either version 2 of the License, or (at your
11: option) any later version.
12:
13: The MPFR Library is distributed in the hope that it will be useful, but
14: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
16: License for more details.
17:
18: You should have received a copy of the GNU Library General Public License
19: along with the MPFR Library; see the file COPYING.LIB. If not, write to
20: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21: MA 02111-1307, USA. */
22:
23: #include <stdio.h>
24: #include "gmp.h"
25: #include "gmp-impl.h"
26: #include "mpfr.h"
27:
28: void
29: #if __STDC__
30: mpfr_get_str_raw(char *digit_ptr, mpfr_srcptr x)
31: #else
32: mpfr_get_str_raw(digit_ptr, x)
33: char *digit_ptr;
34: mpfr_srcptr x;
35: #endif
36: {
37: mp_limb_t *mx, wd, t; long ex, sx, k, l, p;
38:
39: mx = MANT(x);
40: ex = EXP(x);
41: p = PREC(x);
42:
43: if (SIGN(x) < 0) { *digit_ptr = '-'; digit_ptr++; }
44: sprintf(digit_ptr, "0."); digit_ptr += 2;
45:
46: sx = 1+(p-1)/mp_bits_per_limb; /* number of significant limbs */
47: for (k = sx - 1; k >= 0 ; k--)
48: {
49: wd = mx[k];
50: t = ((mp_limb_t)1) << (BITS_PER_MP_LIMB - 1);
51: for (l = BITS_PER_MP_LIMB - 1; l>=0; l--)
52: {
53: if (wd & t)
54: { *digit_ptr = '1'; digit_ptr++; }
55: else
56: { *digit_ptr = '0'; digit_ptr++; }
57: t >>= 1;
58: if (--p==0) { *digit_ptr = '['; digit_ptr++; }
59: }
60: }
61: sprintf(digit_ptr, "]E%ld", ex);
62: }
63:
64: void
65: #if __STDC__
66: mpfr_print_raw(mpfr_srcptr x)
67: #else
68: mpfr_print_raw(x)
69: mpfr_srcptr x;
70: #endif
71: {
72: char *str;
73:
74: if (FLAG_NAN(x)) printf("NaN");
75: else if (!NOTZERO(x)) printf("0");
76: else {
77: /* 3 char for sign + 0 + binary point
78: + ABSSIZE(x) * BITS_PER_MP_LIMB for mantissa
79: + 2 for brackets in mantissa
80: + 1 for 'E'
81: + 11 for exponent (including sign)
82: = 17 + ABSSIZE(x) * BITS_PER_MP_LIMB
83: */
84: str = (char *) malloc((17 + ABSSIZE(x) * BITS_PER_MP_LIMB)*sizeof(char));
85: mpfr_get_str_raw(str, x);
86:
87: printf("%s", str);
88: free(str);
89: }
90: }
91:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>