Back to index

glibc  2.9
printf_fphex.c
Go to the documentation of this file.
00001 /* Print floating point number in hexadecimal notation according to
00002    ISO C99.
00003    Copyright (C) 1997, 1998, 1999, 2000, 2005 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #define PRINT_FPHEX_LONG_DOUBLE \
00022 do {                                                                 \
00023       /* We have 112 bits of mantissa plus one implicit digit.  Since       \
00024         112 bits are representable without rest using hexadecimal           \
00025         digits we use only the implicit digits for the number before        \
00026         the decimal point.  */                                              \
00027       unsigned long long int num0, num1;                             \
00028                                                                      \
00029       assert (sizeof (long double) == 16);                                  \
00030                                                                      \
00031       num0 = (((unsigned long long int) fpnum.ldbl.ieee.mantissa0) << 32      \
00032             | fpnum.ldbl.ieee.mantissa1);                            \
00033       num1 = (((unsigned long long int) fpnum.ldbl.ieee.mantissa2) << 32      \
00034             | fpnum.ldbl.ieee.mantissa3);                            \
00035                                                                      \
00036       zero_mantissa = (num0|num1) == 0;                                     \
00037                                                                      \
00038       if (sizeof (unsigned long int) > 6)                            \
00039        {                                                             \
00040          numstr = _itoa_word (num1, numbuf + sizeof numbuf, 16,             \
00041                             info->spec == 'A');                      \
00042          wnumstr = _itowa_word (num1,                                       \
00043                              wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\
00044                              16, info->spec == 'A');                 \
00045        }                                                             \
00046       else                                                           \
00047        {                                                             \
00048          numstr = _itoa (num1, numbuf + sizeof numbuf, 16,                  \
00049                        info->spec == 'A');                                  \
00050          wnumstr = _itowa (num1,                                     \
00051                          wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),    \
00052                          16, info->spec == 'A');                     \
00053        }                                                             \
00054                                                                      \
00055       while (numstr > numbuf + (sizeof numbuf - 64 / 4))                    \
00056        {                                                             \
00057          *--numstr = '0';                                            \
00058          *--wnumstr = L'0';                                          \
00059        }                                                             \
00060                                                                      \
00061       if (sizeof (unsigned long int) > 6)                            \
00062        {                                                             \
00063          numstr = _itoa_word (num0, numstr, 16, info->spec == 'A');         \
00064          wnumstr = _itowa_word (num0, wnumstr, 16, info->spec == 'A');             \
00065        }                                                             \
00066       else                                                           \
00067        {                                                             \
00068          numstr = _itoa (num0, numstr, 16, info->spec == 'A');              \
00069          wnumstr = _itowa (num0, wnumstr, 16, info->spec == 'A');           \
00070        }                                                             \
00071                                                                      \
00072       /* Fill with zeroes.  */                                              \
00073       while (numstr > numbuf + (sizeof numbuf - 112 / 4))                   \
00074        {                                                             \
00075          *--numstr = '0';                                            \
00076          *--wnumstr = L'0';                                          \
00077        }                                                             \
00078                                                                      \
00079       leading = fpnum.ldbl.ieee.exponent == 0 ? '0' : '1';                  \
00080                                                                      \
00081       exponent = fpnum.ldbl.ieee.exponent;                                  \
00082                                                                      \
00083       if (exponent == 0)                                             \
00084        {                                                             \
00085          if (zero_mantissa)                                          \
00086            expnegative = 0;                                          \
00087          else                                                        \
00088            {                                                         \
00089              /* This is a denormalized number.  */                          \
00090              expnegative = 1;                                               \
00091              exponent = IEEE854_LONG_DOUBLE_BIAS - 1;                       \
00092            }                                                         \
00093        }                                                             \
00094       else if (exponent >= IEEE854_LONG_DOUBLE_BIAS)                        \
00095        {                                                             \
00096          expnegative = 0;                                            \
00097          exponent -= IEEE854_LONG_DOUBLE_BIAS;                              \
00098        }                                                             \
00099       else                                                           \
00100        {                                                             \
00101          expnegative = 1;                                            \
00102          exponent = -(exponent - IEEE854_LONG_DOUBLE_BIAS);                 \
00103        }                                                             \
00104 } while (0)
00105 
00106 #include <stdio-common/printf_fphex.c>