huge_val.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 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 Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. 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. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. Boston, MA 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. # define HUGE_VAL \
  24. (__extension__ \
  25. ((union { unsigned __l __attribute__((__mode__(__DI__))); double __d; }) \
  26. { __l: 0x7ff0000000000000ULL }).__d)
  27. #else /* not GCC */
  28. # include <endian.h>
  29. typedef union { unsigned char __c[8]; double __d; } __huge_val_t;
  30. # if __BYTE_ORDER == __BIG_ENDIAN
  31. # define __HUGE_VAL_bytes { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }
  32. # endif
  33. # if __BYTE_ORDER == __LITTLE_ENDIAN
  34. # define __HUGE_VAL_bytes { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }
  35. # endif
  36. static __huge_val_t __huge_val = { __HUGE_VAL_bytes };
  37. # define HUGE_VAL (__huge_val.__d)
  38. #endif /* GCC. */
  39. /* ISO C 9X extensions: (float) HUGE_VALF and (long double) HUGE_VALL. */
  40. #ifdef __USE_ISOC9X
  41. # ifdef __GNUC__
  42. # define HUGE_VALF \
  43. (__extension__ \
  44. ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; }) \
  45. { __l: 0x7f800000UL }).__d)
  46. # else /* not GCC */
  47. typedef union { unsigned char __c[4]; float __f; } __huge_valf_t;
  48. # if __BYTE_ORDER == __BIG_ENDIAN
  49. # define __HUGE_VALF_bytes { 0x7f, 0x80, 0, 0 }
  50. # endif
  51. # if __BYTE_ORDER == __LITTLE_ENDIAN
  52. # define __HUGE_VALF_bytes { 0, 0, 0x80, 0x7f }
  53. # endif
  54. static __huge_valf_t __huge_valf = { __HUGE_VALF_bytes };
  55. # define HUGE_VALF (__huge_valf.__f)
  56. # endif /* GCC. */
  57. /* Generally there is no separate `long double' format and it is the
  58. same as `double'. */
  59. # define HUGE_VALL HUGE_VAL
  60. #endif /* __USE_ISOC9X. */