huge_val.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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, 95, 96, 97, 98, 99, 2000 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 Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the 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. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, write to the Free
  16. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  17. 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. # 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: 0x000000007ff00000ULL }).__d)
  31. # endif
  32. #else /* not GCC */
  33. # include <endian.h>
  34. typedef union { unsigned char __c[8]; double __d; } __huge_val_t;
  35. # if __BYTE_ORDER == __BIG_ENDIAN
  36. # define __HUGE_VAL_bytes { 0, 0, 0, 0, 0x7f, 0xf0, 0, 0 }
  37. # endif
  38. # if __BYTE_ORDER == __LITTLE_ENDIAN
  39. # define __HUGE_VAL_bytes { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 }
  40. # endif
  41. static __huge_val_t __huge_val = { __HUGE_VAL_bytes };
  42. # define HUGE_VAL (__huge_val.__d)
  43. #endif /* GCC. */
  44. /* ISO C99 extensions: (float) HUGE_VALF and (long double) HUGE_VALL. */
  45. #ifdef __USE_ISOC99
  46. # ifdef __GNUC__
  47. # if __GNUC_PREREQ(2,96)
  48. # define HUGE_VALF (__extension__ 0x1.0p255f)
  49. # else
  50. # define HUGE_VALF \
  51. (__extension__ \
  52. ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; }) \
  53. { __l: 0x7f800000UL }).__d)
  54. # endif
  55. # else /* not GCC */
  56. typedef union { unsigned char __c[4]; float __f; } __huge_valf_t;
  57. # if __BYTE_ORDER == __BIG_ENDIAN
  58. # define __HUGE_VALF_bytes { 0x7f, 0x80, 0, 0 }
  59. # endif
  60. # if __BYTE_ORDER == __LITTLE_ENDIAN
  61. # define __HUGE_VALF_bytes { 0, 0, 0x80, 0x7f }
  62. # endif
  63. static __huge_valf_t __huge_valf = { __HUGE_VALF_bytes };
  64. # define HUGE_VALF (__huge_valf.__f)
  65. # endif /* GCC. */
  66. /* Generally there is no separate `long double' format and it is the
  67. same as `double'. */
  68. # define HUGE_VALL HUGE_VAL
  69. #endif /* __USE_ISOC99. */