huge_val.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* `HUGE_VAL' constants for IEEE 754 machines (where it is infinity).
  2. Used by <stdlib.h> and <math.h> functions for overflow.
  3. v850e version.
  4. Copyright (C) 1992, 95, 96, 97, 98, 99, 2000, 2001 Free Software Foundation, Inc.
  5. This file is part of the GNU C Library.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public License as
  8. published by the Free Software Foundation; either version 2 of the
  9. License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB. If not,
  16. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17. Boston, MA 02111-1307, USA. */
  18. #ifndef _MATH_H
  19. # error "Never use <bits/huge_val.h> directly; include <math.h> instead."
  20. #endif
  21. #include <features.h>
  22. /* IEEE positive infinity (-HUGE_VAL is negative infinity). */
  23. #ifdef __GNUC__
  24. # define HUGE_VAL \
  25. (__extension__ \
  26. ((union { unsigned __l __attribute__((__mode__(__DI__))); double __d; }) \
  27. { __l: 0x000000007ff00000ULL }).__d)
  28. #else /* not GCC */
  29. # include <endian.h>
  30. typedef union { unsigned char __c[8]; double __d; } __huge_val_t;
  31. # if __BYTE_ORDER == __BIG_ENDIAN
  32. # define __HUGE_VAL_bytes { 0, 0, 0, 0, 0x7f, 0xf0, 0, 0 }
  33. # endif
  34. # if __BYTE_ORDER == __LITTLE_ENDIAN
  35. # define __HUGE_VAL_bytes { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 }
  36. # endif
  37. static __huge_val_t __huge_val = { __HUGE_VAL_bytes };
  38. # define HUGE_VAL (__huge_val.__d)
  39. #endif /* GCC. */
  40. /* ISO C 9X extensions: (float) HUGE_VALF and (long double) HUGE_VALL. */
  41. #ifdef __USE_ISOC9X
  42. # ifdef __GNUC__
  43. # define HUGE_VALF \
  44. (__extension__ \
  45. ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; }) \
  46. { __l: 0x7f800000UL }).__d)
  47. # else /* not GCC */
  48. typedef union { unsigned char __c[4]; float __f; } __huge_valf_t;
  49. # if __BYTE_ORDER == __BIG_ENDIAN
  50. # define __HUGE_VALF_bytes { 0x7f, 0x80, 0, 0 }
  51. # endif
  52. # if __BYTE_ORDER == __LITTLE_ENDIAN
  53. # define __HUGE_VALF_bytes { 0, 0, 0x80, 0x7f }
  54. # endif
  55. static __huge_valf_t __huge_valf = { __HUGE_VALF_bytes };
  56. # define HUGE_VALF (__huge_valf.__f)
  57. # endif /* GCC. */
  58. /* Generally there is no separate `long double' format and it is the
  59. same as `double'. */
  60. # define HUGE_VALL HUGE_VAL
  61. #endif /* __USE_ISOC9X. */