]>
Commit | Line | Data |
---|---|---|
a1d84548 | 1 | /* Print floating point number in hexadecimal notation according to ISO C99. |
d4697bc9 | 2 | Copyright (C) 1997-2014 Free Software Foundation, Inc. |
c68cb811 UD |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
c68cb811 UD |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
c68cb811 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
c68cb811 | 18 | |
abfbdde1 UD |
19 | #ifndef LONG_DOUBLE_DENORM_BIAS |
20 | # define LONG_DOUBLE_DENORM_BIAS (IEEE854_LONG_DOUBLE_BIAS - 1) | |
21 | #endif | |
22 | ||
c68cb811 UD |
23 | #define PRINT_FPHEX_LONG_DOUBLE \ |
24 | do { \ | |
25 | /* The "strange" 80 bit format on ix86 and m68k has an explicit \ | |
26 | leading digit in the 64 bit mantissa. */ \ | |
27 | unsigned long long int num; \ | |
1b6adf88 AM |
28 | union ieee854_long_double u; \ |
29 | u.d = fpnum.ldbl; \ | |
c68cb811 UD |
30 | \ |
31 | assert (sizeof (long double) == 12); \ | |
32 | \ | |
1b6adf88 AM |
33 | num = (((unsigned long long int) u.ieee.mantissa0) << 32 \ |
34 | | u.ieee.mantissa1); \ | |
c68cb811 UD |
35 | \ |
36 | zero_mantissa = num == 0; \ | |
37 | \ | |
38 | if (sizeof (unsigned long int) > 6) \ | |
a1d84548 UD |
39 | { \ |
40 | numstr = _itoa_word (num, numbuf + sizeof numbuf, 16, \ | |
41 | info->spec == 'A'); \ | |
b15cb495 UD |
42 | wnumstr = _itowa_word (num, \ |
43 | wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\ | |
44 | 16, info->spec == 'A'); \ | |
a1d84548 | 45 | } \ |
c68cb811 | 46 | else \ |
a1d84548 UD |
47 | { \ |
48 | numstr = _itoa (num, numbuf + sizeof numbuf, 16, info->spec == 'A');\ | |
b15cb495 UD |
49 | wnumstr = _itowa (num, \ |
50 | wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t), \ | |
51 | 16, info->spec == 'A'); \ | |
a1d84548 | 52 | } \ |
c68cb811 UD |
53 | \ |
54 | /* Fill with zeroes. */ \ | |
55 | while (numstr > numbuf + (sizeof numbuf - 64 / 4)) \ | |
a1d84548 UD |
56 | { \ |
57 | *--numstr = '0'; \ | |
58 | *--wnumstr = L'0'; \ | |
59 | } \ | |
c68cb811 UD |
60 | \ |
61 | /* We use a full nibble for the leading digit. */ \ | |
62 | leading = *numstr++; \ | |
a53b7a4e | 63 | wnumstr++; \ |
c68cb811 UD |
64 | \ |
65 | /* We have 3 bits from the mantissa in the leading nibble. \ | |
66 | Therefore we are here using `IEEE854_LONG_DOUBLE_BIAS + 3'. */ \ | |
1b6adf88 | 67 | exponent = u.ieee.exponent; \ |
c68cb811 UD |
68 | \ |
69 | if (exponent == 0) \ | |
70 | { \ | |
71 | if (zero_mantissa) \ | |
72 | expnegative = 0; \ | |
73 | else \ | |
74 | { \ | |
75 | /* This is a denormalized number. */ \ | |
76 | expnegative = 1; \ | |
77 | /* This is a hook for the m68k long double format, where the \ | |
78 | exponent bias is the same for normalized and denormalized \ | |
79 | numbers. */ \ | |
80 | exponent = LONG_DOUBLE_DENORM_BIAS + 3; \ | |
81 | } \ | |
82 | } \ | |
83 | else if (exponent >= IEEE854_LONG_DOUBLE_BIAS + 3) \ | |
84 | { \ | |
85 | expnegative = 0; \ | |
86 | exponent -= IEEE854_LONG_DOUBLE_BIAS + 3; \ | |
87 | } \ | |
88 | else \ | |
89 | { \ | |
90 | expnegative = 1; \ | |
91 | exponent = -(exponent - (IEEE854_LONG_DOUBLE_BIAS + 3)); \ | |
92 | } \ | |
abfbdde1 UD |
93 | } while (0) |
94 | ||
b6ab06ce | 95 | #include <stdio-common/printf_fphex.c> |