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