]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/ieee754/ldbl-128/printf_fphex.c
Update.
[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.
faf2289f 3 Copyright (C) 1997, 1998, 1999, 2000 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
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
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
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21#define PRINT_FPHEX_LONG_DOUBLE \
22do { \
23 /* We have 112 bits of mantissa plus one implicit digit. Since \
24 112 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 \
29 assert (sizeof (long double) == 16); \
30 \
31 num0 = (((unsigned long long int) fpnum.ldbl.ieee.mantissa0) << 32 \
32 | fpnum.ldbl.ieee.mantissa1); \
33 num1 = (((unsigned long long int) fpnum.ldbl.ieee.mantissa2) << 32 \
34 | fpnum.ldbl.ieee.mantissa3); \
35 \
36 zero_mantissa = (num0|num1) == 0; \
37 \
38 if (sizeof (unsigned long int) > 6) \
faf2289f
UD
39 { \
40 numstr = _itoa_word (num1, numbuf + sizeof numbuf, 16, \
41 info->spec == 'A'); \
8a0759d1 42 wnumstr = _itowa_word (num1, \
b15cb495
UD
43 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\
44 16, info->spec == 'A'); \
faf2289f 45 } \
abfbdde1 46 else \
faf2289f
UD
47 { \
48 numstr = _itoa (num1, numbuf + sizeof numbuf, 16, \
49 info->spec == 'A'); \
b15cb495
UD
50 wnumstr = _itowa (num1, \
51 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t), \
52 16, info->spec == 'A'); \
faf2289f 53 } \
abfbdde1
UD
54 \
55 while (numstr > numbuf + (sizeof numbuf - 64 / 4)) \
faf2289f
UD
56 { \
57 *--numstr = '0'; \
58 *--wnumstr = L'0'; \
59 } \
abfbdde1
UD
60 \
61 if (sizeof (unsigned long int) > 6) \
faf2289f
UD
62 { \
63 numstr = _itoa_word (num0, numstr, 16, info->spec == 'A'); \
64 wnumstr = _itowa_word (num0, wnumstr, 16, info->spec == 'A'); \
65 } \
abfbdde1 66 else \
faf2289f
UD
67 { \
68 numstr = _itoa (num0, numstr, 16, info->spec == 'A'); \
69 wnumstr = _itowa (num0, wnumstr, 16, info->spec == 'A'); \
70 } \
abfbdde1
UD
71 \
72 /* Fill with zeroes. */ \
73 while (numstr > numbuf + (sizeof numbuf - 112 / 4)) \
faf2289f
UD
74 { \
75 *--numstr = '0'; \
76 *--wnumstr = L'0'; \
77 } \
abfbdde1
UD
78 \
79 leading = fpnum.ldbl.ieee.exponent == 0 ? '0' : '1'; \
80 \
81 exponent = fpnum.ldbl.ieee.exponent; \
82 \
83 if (exponent == 0) \
84 { \
85 if (zero_mantissa) \
86 expnegative = 0; \
87 else \
88 { \
89 /* This is a denormalized number. */ \
90 expnegative = 1; \
91 exponent = IEEE854_LONG_DOUBLE_BIAS - 1; \
92 } \
93 } \
94 else if (exponent >= IEEE854_LONG_DOUBLE_BIAS) \
95 { \
96 expnegative = 0; \
97 exponent -= IEEE854_LONG_DOUBLE_BIAS; \
98 } \
99 else \
100 { \
101 expnegative = 1; \
102 exponent = -(exponent - IEEE854_LONG_DOUBLE_BIAS); \
103 } \
104} while (0)
105
106#include <sysdeps/generic/printf_fphex.c>