fpmath.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*-
  2. * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
  3. * Copyright (c) 2002 David Schultz <das@FreeBSD.ORG>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. *
  27. * $FreeBSD: src/lib/libc/include/fpmath.h,v 1.4 2008/12/23 22:20:59 marcel Exp $
  28. */
  29. #ifdef __LP64__
  30. #include "amd64_fpmath.h"
  31. #else
  32. #include "i386_fpmath.h"
  33. #endif
  34. #ifdef __linux
  35. #include <features.h>
  36. #include <endian.h>
  37. #endif
  38. #ifdef __APPLE__
  39. #include <machine/endian.h>
  40. #endif
  41. #ifndef _IEEE_WORD_ORDER
  42. #define _IEEE_WORD_ORDER _BYTE_ORDER
  43. #endif
  44. union IEEEf2bits {
  45. float f;
  46. struct {
  47. #if _BYTE_ORDER == _LITTLE_ENDIAN
  48. unsigned int man :23;
  49. unsigned int exp :8;
  50. unsigned int sign :1;
  51. #else /* _BIG_ENDIAN */
  52. unsigned int sign :1;
  53. unsigned int exp :8;
  54. unsigned int man :23;
  55. #endif
  56. } bits;
  57. };
  58. #define DBL_MANH_SIZE 20
  59. #define DBL_MANL_SIZE 32
  60. union IEEEd2bits {
  61. double d;
  62. struct {
  63. #if _BYTE_ORDER == _LITTLE_ENDIAN
  64. #if _IEEE_WORD_ORDER == _LITTLE_ENDIAN
  65. unsigned int manl :32;
  66. #endif
  67. unsigned int manh :20;
  68. unsigned int exp :11;
  69. unsigned int sign :1;
  70. #if _IEEE_WORD_ORDER == _BIG_ENDIAN
  71. unsigned int manl :32;
  72. #endif
  73. #else /* _BIG_ENDIAN */
  74. unsigned int sign :1;
  75. unsigned int exp :11;
  76. unsigned int manh :20;
  77. unsigned int manl :32;
  78. #endif
  79. } bits;
  80. };