huge_val.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. /* IEEE positive infinity (-HUGE_VAL is negative infinity). */
  22. #ifdef __GNUC__
  23. # if __GNUC_PREREQ(2,96)
  24. # define HUGE_VAL (__extension__ 0x1.0p2047)
  25. # else
  26. # define HUGE_VAL \
  27. (__extension__ \
  28. ((union { unsigned __l __attribute__((__mode__(__DI__))); double __d; }) \
  29. { __l: 0x7ff0000000000000ULL }).__d)
  30. # endif
  31. #else /* not GCC */
  32. # include <endian.h>
  33. typedef union { unsigned char __c[8]; double __d; } __huge_val_t;
  34. # if __BYTE_ORDER == __BIG_ENDIAN
  35. # define __HUGE_VAL_bytes { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }
  36. # endif
  37. # if __BYTE_ORDER == __LITTLE_ENDIAN
  38. # define __HUGE_VAL_bytes { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }
  39. # endif
  40. static __huge_val_t __huge_val = { __HUGE_VAL_bytes };
  41. # define HUGE_VAL (__huge_val.__d)
  42. #endif /* GCC. */
  43. /* ISO C99 extensions: (float) HUGE_VALF and (long double) HUGE_VALL. */
  44. #ifdef __USE_ISOC99
  45. # ifdef __GNUC__
  46. # if __GNUC_PREREQ(2,96)
  47. # define HUGE_VALF (__extension__ 0x1.0p255f)
  48. # else
  49. # define HUGE_VALF \
  50. (__extension__ \
  51. ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; }) \
  52. { __l: 0x7f800000UL }).__d)
  53. # endif
  54. # else /* not GCC */
  55. typedef union { unsigned char __c[4]; float __f; } __huge_valf_t;
  56. # if __BYTE_ORDER == __BIG_ENDIAN
  57. # define __HUGE_VALF_bytes { 0x7f, 0x80, 0, 0 }
  58. # endif
  59. # if __BYTE_ORDER == __LITTLE_ENDIAN
  60. # define __HUGE_VALF_bytes { 0, 0, 0x80, 0x7f }
  61. # endif
  62. static __huge_valf_t __huge_valf = { __HUGE_VALF_bytes };
  63. # define HUGE_VALF (__huge_valf.__f)
  64. # endif /* GCC. */
  65. /* Generally there is no separate `long double' format and it is the
  66. same as `double'. */
  67. # define HUGE_VALL HUGE_VAL
  68. #endif /* __USE_ISOC99. */