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 ISO C99.
00002    Copyright (C) 1997, 1998, 1999, 2000, 2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef LONG_DOUBLE_DENORM_BIAS
00021 # define LONG_DOUBLE_DENORM_BIAS (IEEE854_LONG_DOUBLE_BIAS - 1)
00022 #endif
00023 
00024 #define PRINT_FPHEX_LONG_DOUBLE \
00025 do {                                                                 \
00026       /* The "strange" 80 bit format on ix86 and m68k has an explicit       \
00027         leading digit in the 64 bit mantissa.  */                           \
00028       unsigned long long int num;                                    \
00029                                                                      \
00030       assert (sizeof (long double) == 12);                                  \
00031                                                                      \
00032       num = (((unsigned long long int) fpnum.ldbl.ieee.mantissa0) << 32            \
00033             | fpnum.ldbl.ieee.mantissa1);                            \
00034                                                                      \
00035       zero_mantissa = num == 0;                                             \
00036                                                                      \
00037       if (sizeof (unsigned long int) > 6)                            \
00038        {                                                             \
00039          numstr = _itoa_word (num, numbuf + sizeof numbuf, 16,              \
00040                             info->spec == 'A');                      \
00041          wnumstr = _itowa_word (num,                                        \
00042                              wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\
00043                              16, info->spec == 'A');                 \
00044        }                                                             \
00045       else                                                           \
00046        {                                                             \
00047          numstr = _itoa (num, numbuf + sizeof numbuf, 16, info->spec == 'A');\
00048          wnumstr = _itowa (num,                                      \
00049                          wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),    \
00050                          16, info->spec == 'A');                     \
00051        }                                                             \
00052                                                                      \
00053       /* Fill with zeroes.  */                                              \
00054       while (numstr > numbuf + (sizeof numbuf - 64 / 4))                    \
00055        {                                                             \
00056          *--numstr = '0';                                            \
00057          *--wnumstr = L'0';                                          \
00058        }                                                             \
00059                                                                      \
00060       /* We use a full nibble for the leading digit.  */                    \
00061       leading = *numstr++;                                           \
00062                                                                      \
00063       /* We have 3 bits from the mantissa in the leading nibble.            \
00064         Therefore we are here using `IEEE854_LONG_DOUBLE_BIAS + 3'.  */      \
00065       exponent = fpnum.ldbl.ieee.exponent;                                  \
00066                                                                      \
00067       if (exponent == 0)                                             \
00068        {                                                             \
00069          if (zero_mantissa)                                          \
00070            expnegative = 0;                                          \
00071          else                                                        \
00072            {                                                         \
00073              /* This is a denormalized number.  */                          \
00074              expnegative = 1;                                               \
00075              /* This is a hook for the m68k long double format, where the    \
00076                exponent bias is the same for normalized and denormalized    \
00077                numbers.  */                                          \
00078              exponent = LONG_DOUBLE_DENORM_BIAS + 3;                        \
00079            }                                                         \
00080        }                                                             \
00081       else if (exponent >= IEEE854_LONG_DOUBLE_BIAS + 3)                    \
00082        {                                                             \
00083          expnegative = 0;                                            \
00084          exponent -= IEEE854_LONG_DOUBLE_BIAS + 3;                          \
00085        }                                                             \
00086       else                                                           \
00087        {                                                             \
00088          expnegative = 1;                                            \
00089          exponent = -(exponent - (IEEE854_LONG_DOUBLE_BIAS + 3));           \
00090        }                                                             \
00091 } while (0)
00092 
00093 #include <stdio-common/printf_fphex.c>