]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/ldbl-128ibm/printf_fphex.c
Merge glibc-ports into ports/ directory.
[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,2007
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, see
19 <http://www.gnu.org/licenses/>. */
20
21 #define PRINT_FPHEX_LONG_DOUBLE \
22 do { \
23 /* We have 105 bits of mantissa plus one implicit digit. Since \
24 106 bits are representable without rest using hexadecimal \
25 digits we use only the implicit digits for the number before \
26 the decimal point. */ \
27 unsigned long long int num0, num1; \
28 unsigned long long hi, lo; \
29 int ediff; \
30 union ibm_extended_long_double eldbl; \
31 eldbl.d = fpnum.ldbl.d; \
32 \
33 assert (sizeof (long double) == 16); \
34 \
35 lo = ((long long)eldbl.ieee.mantissa2 << 32) | eldbl.ieee.mantissa3; \
36 hi = ((long long)eldbl.ieee.mantissa0 << 32) | eldbl.ieee.mantissa1; \
37 lo <<= 7; /* pre-shift lo to match ieee854. */ \
38 /* If the lower double is not a denomal or zero then set the hidden \
39 53rd bit. */ \
40 if (eldbl.ieee.exponent2 != 0) \
41 lo |= (1ULL << (52 + 7)); \
42 else \
43 lo <<= 1; \
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 + 63) \
48 lo = 0; \
49 else if (ediff > 53) \
50 lo = lo >> (ediff - 53); \
51 else if (eldbl.ieee.exponent2 == 0 && ediff < 53) \
52 lo = lo << (53 - ediff); \
53 if (eldbl.ieee.negative != eldbl.ieee.negative2 \
54 && (eldbl.ieee.exponent2 != 0 || lo != 0L)) \
55 { \
56 lo = (1ULL << 60) - lo; \
57 if (hi == 0L) \
58 { \
59 /* we have a borrow from the hidden bit, so shift left 1. */ \
60 hi = 0xffffffffffffeLL | (lo >> 59); \
61 lo = 0xfffffffffffffffLL & (lo << 1); \
62 eldbl.ieee.exponent--; \
63 } \
64 else \
65 hi--; \
66 } \
67 num1 = (hi << 60) | lo; \
68 num0 = hi >> 4; \
69 \
70 zero_mantissa = (num0|num1) == 0; \
71 \
72 if (sizeof (unsigned long int) > 6) \
73 { \
74 numstr = _itoa_word (num1, numbuf + sizeof numbuf, 16, \
75 info->spec == 'A'); \
76 wnumstr = _itowa_word (num1, \
77 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\
78 16, info->spec == 'A'); \
79 } \
80 else \
81 { \
82 numstr = _itoa (num1, numbuf + sizeof numbuf, 16, \
83 info->spec == 'A'); \
84 wnumstr = _itowa (num1, \
85 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t), \
86 16, info->spec == 'A'); \
87 } \
88 \
89 while (numstr > numbuf + (sizeof numbuf - 64 / 4)) \
90 { \
91 *--numstr = '0'; \
92 *--wnumstr = L'0'; \
93 } \
94 \
95 if (sizeof (unsigned long int) > 6) \
96 { \
97 numstr = _itoa_word (num0, numstr, 16, info->spec == 'A'); \
98 wnumstr = _itowa_word (num0, wnumstr, 16, info->spec == 'A'); \
99 } \
100 else \
101 { \
102 numstr = _itoa (num0, numstr, 16, info->spec == 'A'); \
103 wnumstr = _itowa (num0, wnumstr, 16, info->spec == 'A'); \
104 } \
105 \
106 /* Fill with zeroes. */ \
107 while (numstr > numbuf + (sizeof numbuf - 112 / 4)) \
108 { \
109 *--numstr = '0'; \
110 *--wnumstr = L'0'; \
111 } \
112 \
113 leading = eldbl.ieee.exponent == 0 ? '0' : '1'; \
114 \
115 exponent = eldbl.ieee.exponent; \
116 \
117 if (exponent == 0) \
118 { \
119 if (zero_mantissa) \
120 expnegative = 0; \
121 else \
122 { \
123 /* This is a denormalized number. */ \
124 expnegative = 1; \
125 exponent = IBM_EXTENDED_LONG_DOUBLE_BIAS - 1; \
126 } \
127 } \
128 else if (exponent >= IBM_EXTENDED_LONG_DOUBLE_BIAS) \
129 { \
130 expnegative = 0; \
131 exponent -= IBM_EXTENDED_LONG_DOUBLE_BIAS; \
132 } \
133 else \
134 { \
135 expnegative = 1; \
136 exponent = -(exponent - IBM_EXTENDED_LONG_DOUBLE_BIAS); \
137 } \
138 } while (0)
139
140 #include <stdio-common/printf_fphex.c>