huge_val.h 2.8 KB

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