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