printf_fphex.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Print floating point number in hexadecimal notation according to ISO C99.
  2. Copyright (C) 1997-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef LONG_DOUBLE_DENORM_BIAS
  16. # define LONG_DOUBLE_DENORM_BIAS (IEEE854_LONG_DOUBLE_BIAS - 1)
  17. #endif
  18. #define PRINT_FPHEX_LONG_DOUBLE \
  19. do { \
  20. /* The "strange" 80 bit format on ix86 and m68k has an explicit \
  21. leading digit in the 64 bit mantissa. */ \
  22. unsigned long long int num; \
  23. union ieee854_long_double u; \
  24. u.d = fpnum.ldbl; \
  25. \
  26. assert (sizeof (long double) == 12); \
  27. \
  28. num = (((unsigned long long int) u.ieee.mantissa0) << 32 \
  29. | u.ieee.mantissa1); \
  30. \
  31. zero_mantissa = num == 0; \
  32. \
  33. if (sizeof (unsigned long int) > 6) \
  34. numstr = _itoa_word (num, numbuf + sizeof numbuf, 16, \
  35. info->spec == 'A'); \
  36. else \
  37. numstr = _itoa (num, numbuf + sizeof numbuf, 16, info->spec == 'A'); \
  38. \
  39. /* Fill with zeroes. */ \
  40. while (numstr > numbuf + (sizeof numbuf - 64 / 4)) \
  41. *--numstr = '0'; \
  42. \
  43. /* We use a full nibble for the leading digit. */ \
  44. leading = *numstr++; \
  45. \
  46. /* We have 3 bits from the mantissa in the leading nibble. \
  47. Therefore we are here using `IEEE854_LONG_DOUBLE_BIAS + 3'. */ \
  48. exponent = u.ieee.exponent; \
  49. \
  50. if (exponent == 0) \
  51. { \
  52. if (zero_mantissa) \
  53. expnegative = 0; \
  54. else \
  55. { \
  56. /* This is a denormalized number. */ \
  57. expnegative = 1; \
  58. /* This is a hook for the m68k long double format, where the \
  59. exponent bias is the same for normalized and denormalized \
  60. numbers. */ \
  61. exponent = LONG_DOUBLE_DENORM_BIAS + 3; \
  62. } \
  63. } \
  64. else if (exponent >= IEEE854_LONG_DOUBLE_BIAS + 3) \
  65. { \
  66. expnegative = 0; \
  67. exponent -= IEEE854_LONG_DOUBLE_BIAS + 3; \
  68. } \
  69. else \
  70. { \
  71. expnegative = 1; \
  72. exponent = -(exponent - (IEEE854_LONG_DOUBLE_BIAS + 3)); \
  73. } \
  74. } while (0)
  75. #include <stdio-common/printf_fphex.c>