]>
git.ipfire.org Git - thirdparty/glibc.git/blob - 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
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
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.
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.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 #define PRINT_FPHEX_LONG_DOUBLE \
24 /* We have 105 bits of mantissa plus one implicit digit. Since \
25 106 bits are representable without rest using hexadecimal \
26 digits we use only the implicit digits for the number before \
27 the decimal point. */ \
28 unsigned long long int num0, num1; \
29 unsigned long long hi, lo; \
31 union ibm_extended_long_double eldbl; \
32 eldbl.d = fpnum.ldbl.d; \
34 assert (sizeof (long double) == 16); \
36 lo = ((long long)eldbl.ieee.mantissa2 << 32) | eldbl.ieee.mantissa3; \
37 hi = ((long long)eldbl.ieee.mantissa0 << 32) | eldbl.ieee.mantissa1; \
38 /* If the lower double is not a denomal or zero then set the hidden \
40 if (eldbl.ieee.exponent2 > 0x001) \
43 lo = lo << 7; /* pre-shift lo to match ieee854. */ \
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; \
48 lo = lo >> (ediff-53); \
51 if ((eldbl.ieee.negative != eldbl.ieee.negative2) \
52 && ((eldbl.ieee.exponent2 != 0) && (lo != 0L))) \
54 lo = (1ULL << 60) - lo; \
57 /* we have a borrow from the hidden bit, so shift left 1. */ \
58 hi = 0xffffffffffffeLL | (lo >> 59); \
59 lo = 0xfffffffffffffffLL & (lo << 1); \
60 eldbl.ieee.exponent--; \
65 num1 = (hi << 60) | lo; \
68 zero_mantissa = (num0|num1) == 0; \
70 if (sizeof (unsigned long int) > 6) \
72 numstr = _itoa_word (num1, numbuf + sizeof numbuf, 16, \
74 wnumstr = _itowa_word (num1, \
75 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\
76 16, info->spec == 'A'); \
80 numstr = _itoa (num1, numbuf + sizeof numbuf, 16, \
82 wnumstr = _itowa (num1, \
83 wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t), \
84 16, info->spec == 'A'); \
87 while (numstr > numbuf + (sizeof numbuf - 64 / 4)) \
93 if (sizeof (unsigned long int) > 6) \
95 numstr = _itoa_word (num0, numstr, 16, info->spec == 'A'); \
96 wnumstr = _itowa_word (num0, wnumstr, 16, info->spec == 'A'); \
100 numstr = _itoa (num0, numstr, 16, info->spec == 'A'); \
101 wnumstr = _itowa (num0, wnumstr, 16, info->spec == 'A'); \
104 /* Fill with zeroes. */ \
105 while (numstr > numbuf + (sizeof numbuf - 112 / 4)) \
111 leading = eldbl.ieee.exponent == 0 ? '0' : '1'; \
113 exponent = eldbl.ieee.exponent; \
121 /* This is a denormalized number. */ \
123 exponent = IBM_EXTENDED_LONG_DOUBLE_BIAS - 1; \
126 else if (exponent >= IBM_EXTENDED_LONG_DOUBLE_BIAS) \
129 exponent -= IBM_EXTENDED_LONG_DOUBLE_BIAS; \
134 exponent = -(exponent - IBM_EXTENDED_LONG_DOUBLE_BIAS); \
138 #include <stdio-common/printf_fphex.c>