Update copyright notices with scripts/update-copyrights.
[jlayton/glibc.git] / sysdeps / ieee754 / ldbl-128 / printf_fphex.c
1 /* Print floating point number in hexadecimal notation according to
2    ISO C99.
3    Copyright (C) 1997-2013 Free Software Foundation, Inc.
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 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.
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    Lesser General Public License for more details.
15
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/>.  */
19
20 #define PRINT_FPHEX_LONG_DOUBLE \
21 do {                                                                          \
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;                                      \
27                                                                               \
28       assert (sizeof (long double) == 16);                                    \
29                                                                               \
30       num0 = (((unsigned long long int) fpnum.ldbl.ieee.mantissa0) << 32      \
31              | fpnum.ldbl.ieee.mantissa1);                                    \
32       num1 = (((unsigned long long int) fpnum.ldbl.ieee.mantissa2) << 32      \
33              | fpnum.ldbl.ieee.mantissa3);                                    \
34                                                                               \
35       zero_mantissa = (num0|num1) == 0;                                       \
36                                                                               \
37       if (sizeof (unsigned long int) > 6)                                     \
38         {                                                                     \
39           numstr = _itoa_word (num1, numbuf + sizeof numbuf, 16,              \
40                                info->spec == 'A');                            \
41           wnumstr = _itowa_word (num1,                                        \
42                                  wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\
43                                  16, info->spec == 'A');                      \
44         }                                                                     \
45       else                                                                    \
46         {                                                                     \
47           numstr = _itoa (num1, numbuf + sizeof numbuf, 16,                   \
48                           info->spec == 'A');                                 \
49           wnumstr = _itowa (num1,                                             \
50                             wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),    \
51                             16, info->spec == 'A');                           \
52         }                                                                     \
53                                                                               \
54       while (numstr > numbuf + (sizeof numbuf - 64 / 4))                      \
55         {                                                                     \
56           *--numstr = '0';                                                    \
57           *--wnumstr = L'0';                                                  \
58         }                                                                     \
59                                                                               \
60       if (sizeof (unsigned long int) > 6)                                     \
61         {                                                                     \
62           numstr = _itoa_word (num0, numstr, 16, info->spec == 'A');          \
63           wnumstr = _itowa_word (num0, wnumstr, 16, info->spec == 'A');       \
64         }                                                                     \
65       else                                                                    \
66         {                                                                     \
67           numstr = _itoa (num0, numstr, 16, info->spec == 'A');               \
68           wnumstr = _itowa (num0, wnumstr, 16, info->spec == 'A');            \
69         }                                                                     \
70                                                                               \
71       /* Fill with zeroes.  */                                                \
72       while (numstr > numbuf + (sizeof numbuf - 112 / 4))                     \
73         {                                                                     \
74           *--numstr = '0';                                                    \
75           *--wnumstr = L'0';                                                  \
76         }                                                                     \
77                                                                               \
78       leading = fpnum.ldbl.ieee.exponent == 0 ? '0' : '1';                    \
79                                                                               \
80       exponent = fpnum.ldbl.ieee.exponent;                                    \
81                                                                               \
82       if (exponent == 0)                                                      \
83         {                                                                     \
84           if (zero_mantissa)                                                  \
85             expnegative = 0;                                                  \
86           else                                                                \
87             {                                                                 \
88               /* This is a denormalized number.  */                           \
89               expnegative = 1;                                                \
90               exponent = IEEE854_LONG_DOUBLE_BIAS - 1;                        \
91             }                                                                 \
92         }                                                                     \
93       else if (exponent >= IEEE854_LONG_DOUBLE_BIAS)                          \
94         {                                                                     \
95           expnegative = 0;                                                    \
96           exponent -= IEEE854_LONG_DOUBLE_BIAS;                               \
97         }                                                                     \
98       else                                                                    \
99         {                                                                     \
100           expnegative = 1;                                                    \
101           exponent = -(exponent - IEEE854_LONG_DOUBLE_BIAS);                  \
102         }                                                                     \
103 } while (0)
104
105 #include <stdio-common/printf_fphex.c>