]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/ieee754/ldbl-128/printf_fphex.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / ieee754 / ldbl-128 / printf_fphex.c
CommitLineData
abfbdde1 1/* Print floating point number in hexadecimal notation according to
ec751a23 2 ISO C99.
d4697bc9 3 Copyright (C) 1997-2014 Free Software Foundation, Inc.
abfbdde1
UD
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
abfbdde1
UD
10
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
41bdb6e2 14 Lesser General Public License for more details.
abfbdde1 15
41bdb6e2 16 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
abfbdde1
UD
19
20#define PRINT_FPHEX_LONG_DOUBLE \
21do { \
22 /* We have 112 bits of mantissa plus one implicit digit. Since \
23 112 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; \
1b6adf88
AM
27 union ieee854_long_double u; \
28 u.d = fpnum.ldbl; \
abfbdde1
UD
29 \
30 assert (sizeof (long double) == 16); \
31 \
1b6adf88
AM
32 num0 = (((unsigned long long int) u.ieee.mantissa0) << 32 \
33 | u.ieee.mantissa1); \
34 num1 = (((unsigned long long int) u.ieee.mantissa2) << 32 \
35 | u.ieee.mantissa3); \
abfbdde1
UD
36 \
37 zero_mantissa = (num0|num1) == 0; \
38 \
39 if (sizeof (unsigned long int) > 6) \
faf2289f
UD
40 { \
41 numstr = _itoa_word (num1, numbuf + sizeof numbuf, 16, \
42 info->spec == 'A'); \
8a0759d1 43 wnumstr = _itowa_word (num1, \
b15cb495
UD
44 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\
45 16, info->spec == 'A'); \
faf2289f 46 } \
abfbdde1 47 else \
faf2289f
UD
48 { \
49 numstr = _itoa (num1, numbuf + sizeof numbuf, 16, \
50 info->spec == 'A'); \
b15cb495
UD
51 wnumstr = _itowa (num1, \
52 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t), \
53 16, info->spec == 'A'); \
faf2289f 54 } \
abfbdde1
UD
55 \
56 while (numstr > numbuf + (sizeof numbuf - 64 / 4)) \
faf2289f
UD
57 { \
58 *--numstr = '0'; \
59 *--wnumstr = L'0'; \
60 } \
abfbdde1
UD
61 \
62 if (sizeof (unsigned long int) > 6) \
faf2289f
UD
63 { \
64 numstr = _itoa_word (num0, numstr, 16, info->spec == 'A'); \
65 wnumstr = _itowa_word (num0, wnumstr, 16, info->spec == 'A'); \
66 } \
abfbdde1 67 else \
faf2289f
UD
68 { \
69 numstr = _itoa (num0, numstr, 16, info->spec == 'A'); \
70 wnumstr = _itowa (num0, wnumstr, 16, info->spec == 'A'); \
71 } \
abfbdde1
UD
72 \
73 /* Fill with zeroes. */ \
74 while (numstr > numbuf + (sizeof numbuf - 112 / 4)) \
faf2289f
UD
75 { \
76 *--numstr = '0'; \
77 *--wnumstr = L'0'; \
78 } \
abfbdde1 79 \
1b6adf88 80 leading = u.ieee.exponent == 0 ? '0' : '1'; \
abfbdde1 81 \
1b6adf88 82 exponent = u.ieee.exponent; \
abfbdde1
UD
83 \
84 if (exponent == 0) \
85 { \
86 if (zero_mantissa) \
87 expnegative = 0; \
88 else \
89 { \
90 /* This is a denormalized number. */ \
91 expnegative = 1; \
92 exponent = IEEE854_LONG_DOUBLE_BIAS - 1; \
93 } \
94 } \
95 else if (exponent >= IEEE854_LONG_DOUBLE_BIAS) \
96 { \
97 expnegative = 0; \
98 exponent -= IEEE854_LONG_DOUBLE_BIAS; \
99 } \
100 else \
101 { \
102 expnegative = 1; \
103 exponent = -(exponent - IEEE854_LONG_DOUBLE_BIAS); \
104 } \
105} while (0)
106
2826ac7e 107#include <stdio-common/printf_fphex.c>