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,2001,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                                                                      \
00031       num = (((unsigned long long int) fpnum.ldbl.ieee.mantissa0) << 32            \
00032             | fpnum.ldbl.ieee.mantissa1);                            \
00033                                                                      \
00034       zero_mantissa = num == 0;                                             \
00035                                                                      \
00036       if (sizeof (unsigned long int) > 6)                            \
00037        {                                                             \
00038          numstr = _itoa_word (num, numbuf + sizeof numbuf, 16,              \
00039                             info->spec == 'A');                      \
00040          wnumstr = _itowa_word (num,                                        \
00041                              wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),\
00042                              16, info->spec == 'A');                 \
00043        }                                                             \
00044       else                                                           \
00045        {                                                             \
00046          numstr = _itoa (num, numbuf + sizeof numbuf, 16, info->spec == 'A');\
00047          wnumstr = _itowa (num,                                      \
00048                          wnumbuf + sizeof (wnumbuf) / sizeof (wchar_t),    \
00049                          16, info->spec == 'A');                     \
00050        }                                                             \
00051                                                                      \
00052       /* Fill with zeroes.  */                                              \
00053       while (numstr > numbuf + (sizeof numbuf - 64 / 4))                    \
00054        {                                                             \
00055          *--numstr = '0';                                            \
00056          *--wnumstr = L'0';                                          \
00057        }                                                             \
00058                                                                      \
00059       /* We use a full nibble for the leading digit.  */                    \
00060       leading = *numstr++;                                           \
00061                                                                      \
00062       /* We have 3 bits from the mantissa in the leading nibble.            \
00063         Therefore we are here using `IEEE854_LONG_DOUBLE_BIAS + 3'.  */      \
00064       exponent = fpnum.ldbl.ieee.exponent;                                  \
00065                                                                      \
00066       if (exponent == 0)                                             \
00067        {                                                             \
00068          if (zero_mantissa)                                          \
00069            expnegative = 0;                                          \
00070          else                                                        \
00071            {                                                         \
00072              /* This is a denormalized number.  */                          \
00073              expnegative = 1;                                               \
00074              /* This is a hook for the m68k long double format, where the    \
00075                exponent bias is the same for normalized and denormalized    \
00076                numbers.  */                                          \
00077              exponent = LONG_DOUBLE_DENORM_BIAS + 3;                        \
00078            }                                                         \
00079        }                                                             \
00080       else if (exponent >= IEEE854_LONG_DOUBLE_BIAS + 3)                    \
00081        {                                                             \
00082          expnegative = 0;                                            \
00083          exponent -= IEEE854_LONG_DOUBLE_BIAS + 3;                          \
00084        }                                                             \
00085       else                                                           \
00086        {                                                             \
00087          expnegative = 1;                                            \
00088          exponent = -(exponent - (IEEE854_LONG_DOUBLE_BIAS + 3));           \
00089        }                                                             \
00090 } while (0)
00091 
00092 #include <stdio-common/printf_fphex.c>