home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / unixlib / h / ieee754 < prev    next >
Encoding:
Text File  |  2006-09-17  |  3.7 KB  |  178 lines

  1. /* IEEE Floating Point definitions for RISC OS.
  2.    Copyright (c) 2005 UnixLib Developers.  */
  3.  
  4. #ifndef __MACHINE_IEEE754_H
  5. #define __MACHINE_IEEE754_H 1
  6.  
  7. #ifndef __UNIXLIB_FEATURES_H
  8. #include <features.h>
  9. #endif
  10.  
  11. #include <endian.h>
  12.  
  13. /* There are two models in use:
  14.      The ARM/FPA model or hard-float ABI
  15.      The soft-floating point model or soft-float ABI.   */
  16.  
  17. __BEGIN_DECLS
  18.  
  19. union ieee754_float
  20. {
  21.   float f;
  22.  
  23.   /* This is the IEEE 754 single-precision format for little-endian
  24.      architectures.  */
  25.   struct
  26.   {
  27. #if __FLOAT_BIT_ORDER == __LITTLE_ENDIAN
  28.     /* ARM/FPA.  */
  29.     unsigned int mantissa:23;
  30.     unsigned int exponent:8;
  31.     unsigned int negative:1;
  32. #else
  33.     unsigned int negative:1;
  34.     unsigned int exponent:8;
  35.     unsigned int mantissa:23;
  36. #endif
  37.   } ieee;
  38.  
  39.   /* This format makes it easier to see if a NaN is a signalling NaN.  */
  40.   struct
  41.   {
  42. #if __FLOAT_BIT_ORDER == __LITTLE_ENDIAN
  43.     /* ARM/FPA.  */
  44.     unsigned int mantissa:22;
  45.     unsigned int quiet_nan:1;
  46.     unsigned int exponent:8;
  47.     unsigned int negative:1;
  48. #else
  49.     unsigned int negative:1;
  50.     unsigned int exponent:8;
  51.     unsigned int quiet_nan:1;
  52.     unsigned int mantissa:22;
  53. #endif
  54.   } ieee_nan;
  55. };
  56.  
  57. #define IEEE754_FLOAT_BIAS    0x7f /* Added to exponent.  */
  58.  
  59.  
  60. union ieee754_double
  61. {
  62.   double d;
  63.  
  64.   /* This is the IEEE 754 double-precision format.  */
  65.   struct
  66.   {
  67. #if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
  68.     unsigned int mantissa1:32;
  69. #endif
  70.  
  71. #if __FLOAT_BIT_ORDER == __LITTLE_ENDIAN
  72.     unsigned int mantissa0:20;
  73.     unsigned int exponent:11;
  74.     unsigned int negative:1;
  75. #else
  76.     unsigned int negative:1;
  77.     unsigned int exponent:11;
  78.     unsigned int mantissa0:20;
  79. #endif
  80.  
  81. #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  82.     unsigned int mantissa1:32;
  83. #endif
  84.   } ieee;
  85.   
  86.   /* This format makes it easier to see if a NaN is a signalling NaN.  */
  87.   struct
  88.   {
  89. #if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
  90.     unsigned int mantissa1:32;
  91. #endif
  92.  
  93. #if __FLOAT_BIT_ORDER == __LITTLE_ENDIAN
  94.     unsigned int mantissa0:19;
  95.     unsigned int quiet_nan:1;
  96.     unsigned int exponent:11;
  97.     unsigned int negative:1;
  98. #else /* ARM/FPA */
  99.     unsigned int negative:1;
  100.     unsigned int exponent:11;
  101.     unsigned int quiet_nan:1;
  102.     unsigned int mantissa0:19;
  103. #endif
  104.  
  105. #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  106.     unsigned int mantissa1:32;
  107. #endif
  108.   } ieee_nan;
  109. };
  110.  
  111. #define IEEE754_DOUBLE_BIAS    0x3ff /* Added to exponent.  */
  112.  
  113.  
  114. union ieee854_long_double
  115. {
  116.   long double d;
  117.  
  118.   /* This is the IEEE 854 double-extended-precision format.  */
  119.   struct
  120.   {
  121. #if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
  122.     unsigned int mantissa0:32;
  123.     unsigned int mantissa1:32;
  124. #endif
  125.  
  126. #if __FLOAT_BIT_ORDER == __LITTLE_ENDIAN
  127.     unsigned int exponent:15; 
  128.     unsigned int empty:16;
  129.     unsigned int negative:1;
  130. #else
  131.     unsigned int negative:1;
  132.     unsigned int empty:16;
  133.     unsigned int exponent:15;
  134. #endif
  135.  
  136. #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  137.     unsigned int mantissa1:32;
  138.     unsigned int mantissa0:32;
  139. #endif
  140.   } ieee;
  141.  
  142.   /* This is for NaNs in the IEEE 854 double-extended-precision format.  */
  143.   struct
  144.   {
  145. #if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
  146.     unsigned int mantissa1:32;
  147.     unsigned int mantissa0:30;
  148.     unsigned int quiet_nan:1;
  149.     unsigned int one:1;
  150. #endif
  151.  
  152. #if __FLOAT_BIT_ORDER == __LITTLE_ENDIAN
  153.     unsigned int exponent:15;
  154.     unsigned int empty:16;
  155.     unsigned int negative:1;
  156. #else /* ARM/FPA */
  157.     unsigned int negative:1;
  158.     unsigned int empty:16;
  159.     unsigned int exponent:15;
  160. #endif
  161. #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
  162.     unsigned int one:1;
  163.     unsigned int quiet_nan:1;
  164.     unsigned int mantissa1:30;
  165.     unsigned int mantissa0:32;
  166. #endif
  167.   } ieee_nan;
  168. };
  169.  
  170. #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
  171.  
  172.  
  173. extern double __ieee754_exp (double __x);
  174.  
  175. __END_DECLS
  176.  
  177. #endif
  178.