huge_val.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* `HUGE_VAL' constants for IEEE 754 machines (where it is infinity).
  2. Used by <stdlib.h> and <math.h> functions for overflow.
  3. Copyright (C) 1992, 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #ifndef _MATH_H
  18. # error "Never use <bits/huge_val.h> directly; include <math.h> instead."
  19. #endif
  20. #include <features.h>
  21. #include <bits/wordsize.h>
  22. /* IEEE positive infinity (-HUGE_VAL is negative infinity). */
  23. #ifdef __GNUC__
  24. # if __GNUC_PREREQ(2,96)
  25. # define HUGE_VAL (__extension__ 0x1.0p2047)
  26. # else
  27. # define HUGE_VAL \
  28. (__extension__ \
  29. ((union { unsigned __l __attribute__((__mode__(__DI__))); double __d; }) \
  30. { __l: 0x7ff0000000000000ULL }).__d)
  31. # endif
  32. #else /* not GCC */
  33. typedef union { unsigned char __c[8]; double __d; } __huge_val_t;
  34. # define __HUGE_VAL_bytes { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }
  35. static __huge_val_t __huge_val = { __HUGE_VAL_bytes };
  36. # define HUGE_VAL (__huge_val.__d)
  37. #endif /* GCC. */
  38. /* ISO C99 extensions: (float) HUGE_VALF and (long double) HUGE_VALL. */
  39. #ifdef __USE_ISOC99
  40. # if __GNUC_PREREQ(2,96)
  41. # define HUGE_VALF (__extension__ 0x1.0p255f)
  42. # if __WORDSIZE == 32
  43. # define HUGE_VALL HUGE_VAL
  44. # else
  45. /* Sparc64 uses IEEE 754 128bit long double */
  46. # define HUGE_VALL (__extension__ 0x1.0p32767L)
  47. # endif
  48. # else
  49. # ifdef __GNUC__
  50. # define HUGE_VALF \
  51. (__extension__ \
  52. ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; }) \
  53. { __l: 0x7f800000UL }).__d)
  54. # else /* not GCC */
  55. typedef union { unsigned char __c[4]; float __f; } __huge_valf_t;
  56. # define __HUGE_VALF_bytes { 0x7f, 0x80, 0, 0 }
  57. static __huge_valf_t __huge_valf = { __HUGE_VALF_bytes };
  58. # define HUGE_VALF (__huge_valf.__f)
  59. # endif /* GCC. */
  60. # if __WORDSIZE == 32
  61. /* Sparc32 has IEEE 754 64bit long double */
  62. # define HUGE_VALL HUGE_VAL
  63. # else
  64. /* Sparc64 uses IEEE 754 128bit long double */
  65. # ifdef __GNUC__
  66. # define HUGE_VALL \
  67. (__extension__ \
  68. ((union { struct { unsigned long __h, __l; } __i; long double __d; }) \
  69. { __i: { __h: 0x7fff000000000000UL, __l: 0 } }).__d)
  70. # else /* not GCC */
  71. typedef union { unsigned char __c[16]; long double __d; } __huge_vall_t;
  72. # define __HUGE_VALL_bytes { 0x7f, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
  73. static __huge_vall_t __huge_vall = { __HUGE_VALL_bytes };
  74. # define HUGE_VALL (__huge_vall.__d)
  75. # endif /* GCC. */
  76. # endif
  77. # endif /* GCC 2.95. */
  78. #endif /* __USE_ISOC99. */