]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/ldbl-128ibm/printf_fphex.c
2006-01-27 Dwayne Grant McConnell <decimal@us.ibm.com>
[thirdparty/glibc.git] / sysdeps / ieee754 / ldbl-128ibm / printf_fphex.c
1 /* Print floating point number in hexadecimal notation according to ISO C99.
2 Copyright (C) 1997,1998,1999,2000,2001,2002,2004,2006
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
21
22 #define PRINT_FPHEX_LONG_DOUBLE \
23 do { \
24 /* We have 105 bits of mantissa plus one implicit digit. Since \
25 106 bits are representable without rest using hexadecimal \
26 digits we use only the implicit digits for the number before \
27 the decimal point. */ \
28 unsigned long long int num0, num1; \
29 unsigned long long hi, lo; \
30 int ediff; \
31 union ibm_extended_long_double eldbl; \
32 eldbl.d = fpnum.ldbl.d; \
33 \
34 assert (sizeof (long double) == 16); \
35 \
36 lo = ((long long)eldbl.ieee.mantissa2 << 32) | eldbl.ieee.mantissa3; \
37 hi = ((long long)eldbl.ieee.mantissa0 << 32) | eldbl.ieee.mantissa1; \
38 /* If the lower double is not a denomal or zero then set the hidden \
39 53rd bit. */ \
40 if (eldbl.ieee.exponent2 > 0x001) \
41 { \
42 lo |= (1ULL << 52); \
43 lo = lo << 7; /* pre-shift lo to match ieee854. */ \
44 /* The lower double is normalized separately from the upper. We \
45 may need to adjust the lower manitissa to reflect this. */ \
46 ediff = eldbl.ieee.exponent - eldbl.ieee.exponent2; \
47 if (ediff > 53) \
48 lo = lo >> (ediff-53); \
49 } \
50 \
51 if ((eldbl.ieee.negative != eldbl.ieee.negative2) \
52 && ((eldbl.ieee.exponent2 != 0) && (lo != 0L))) \
53 { \
54 lo = (1ULL << 60) - lo; \
55 if (hi == 0L) \
56 { \
57 /* we have a borrow from the hidden bit, so shift left 1. */ \
58 hi = 0xffffffffffffeLL | (lo >> 59); \
59 lo = 0xfffffffffffffffLL & (lo << 1); \
60 eldbl.ieee.exponent--; \
61 } \
62 else \
63 hi--; \
64 } \
65 num1 = (hi << 60) | lo; \
66 num0 = hi >> 4; \
67 \
68 zero_mantissa = (num0|num1) == 0; \
69 \
70 if (sizeof (unsigned long int) > 6) \
71 { \
72 numstr = _itoa_word (num1, numbuf + sizeof numbuf, 16, \
73 info->spec == 'A'); \
74 wnumstr = _itowa_word (num1, \
75 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\
76 16, info->spec == 'A'); \
77 } \
78 else \
79 { \
80 numstr = _itoa (num1, numbuf + sizeof numbuf, 16, \
81 info->spec == 'A'); \
82 wnumstr = _itowa (num1, \
83 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t), \
84 16, info->spec == 'A'); \
85 } \
86 \
87 while (numstr > numbuf + (sizeof numbuf - 64 / 4)) \
88 { \
89 *--numstr = '0'; \
90 *--wnumstr = L'0'; \
91 } \
92 \
93 if (sizeof (unsigned long int) > 6) \
94 { \
95 numstr = _itoa_word (num0, numstr, 16, info->spec == 'A'); \
96 wnumstr = _itowa_word (num0, wnumstr, 16, info->spec == 'A'); \
97 } \
98 else \
99 { \
100 numstr = _itoa (num0, numstr, 16, info->spec == 'A'); \
101 wnumstr = _itowa (num0, wnumstr, 16, info->spec == 'A'); \
102 } \
103 \
104 /* Fill with zeroes. */ \
105 while (numstr > numbuf + (sizeof numbuf - 112 / 4)) \
106 { \
107 *--numstr = '0'; \
108 *--wnumstr = L'0'; \
109 } \
110 \
111 leading = eldbl.ieee.exponent == 0 ? '0' : '1'; \
112 \
113 exponent = eldbl.ieee.exponent; \
114 \
115 if (exponent == 0) \
116 { \
117 if (zero_mantissa) \
118 expnegative = 0; \
119 else \
120 { \
121 /* This is a denormalized number. */ \
122 expnegative = 1; \
123 exponent = IBM_EXTENDED_LONG_DOUBLE_BIAS - 1; \
124 } \
125 } \
126 else if (exponent >= IBM_EXTENDED_LONG_DOUBLE_BIAS) \
127 { \
128 expnegative = 0; \
129 exponent -= IBM_EXTENDED_LONG_DOUBLE_BIAS; \
130 } \
131 else \
132 { \
133 expnegative = 1; \
134 exponent = -(exponent - IBM_EXTENDED_LONG_DOUBLE_BIAS); \
135 } \
136 } while (0)
137
138 #include <stdio-common/printf_fphex.c>