Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

431 lines
15 KiB

  1. /*
  2. File: fenv.h
  3. Contains: Floating-Point environment for PowerPC and 68K
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 1987-2001 by Apple Computer, Inc., all rights reserved.
  6. Bugs?: For bug reports, consult the following page on
  7. the World Wide Web:
  8. http://developer.apple.com/bugreporter/
  9. */
  10. #ifndef __FENV__
  11. #define __FENV__
  12. #ifndef __CONDITIONALMACROS__
  13. #include <ConditionalMacros.h>
  14. #endif
  15. #if PRAGMA_ONCE
  16. #pragma once
  17. #endif
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #if PRAGMA_IMPORT
  22. #pragma import on
  23. #endif
  24. #if PRAGMA_STRUCT_ALIGN
  25. #pragma options align=mac68k
  26. #elif PRAGMA_STRUCT_PACKPUSH
  27. #pragma pack(push, 2)
  28. #elif PRAGMA_STRUCT_PACK
  29. #pragma pack(2)
  30. #endif
  31. #if TARGET_RT_MAC_MACHO && defined(__MATH__)
  32. /* these types were already defined in math.h */
  33. #else
  34. #if TARGET_OS_MAC
  35. /*
  36. A collection of functions designed to provide access to the floating
  37. point environment for numerical programming. It is modeled after
  38. the floating-point requirements in C9X.
  39. The file <fenv.h> declares many functions in support of numerical
  40. programming. It provides a set of environmental controls similar to
  41. the ones found in <SANE.h>. Programs that test flags or run under
  42. non-default modes must do so under the effect of an enabling
  43. "fenv_access" pragma.
  44. */
  45. /********************************************************************************
  46. * *
  47. * fenv_t is a type for representing the entire floating-point *
  48. * environment in a single object. *
  49. * *
  50. * fexcept_t is a type for representing the floating-point *
  51. * exception flag state collectively. *
  52. * *
  53. ********************************************************************************/
  54. #if TARGET_CPU_PPC
  55. typedef long fenv_t;
  56. typedef long fexcept_t;
  57. /* Definitions of floating-point exception macros */
  58. enum {
  59. FE_INEXACT = 0x02000000,
  60. FE_DIVBYZERO = 0x04000000,
  61. FE_UNDERFLOW = 0x08000000,
  62. FE_OVERFLOW = 0x10000000,
  63. FE_INVALID = 0x20000000,
  64. FE_ALL_EXCEPT = 0x3E000000 /* FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID*/
  65. };
  66. /* Definitions of rounding direction macros */
  67. enum {
  68. FE_TONEAREST = 0x00000000,
  69. FE_TOWARDZERO = 0x00000001,
  70. FE_UPWARD = 0x00000002,
  71. FE_DOWNWARD = 0x00000003
  72. };
  73. #endif /* TARGET_CPU_PPC */
  74. #if TARGET_CPU_68K
  75. #if TARGET_RT_MAC_68881
  76. typedef long fexcept_t;
  77. struct fenv_t {
  78. long FPCR;
  79. long FPSR;
  80. };
  81. typedef struct fenv_t fenv_t;
  82. enum {
  83. FE_INEXACT = 0x00000008, /* ((long)(8)) */
  84. FE_DIVBYZERO = 0x00000010, /* ((long)(16)) */
  85. FE_UNDERFLOW = 0x00000020, /* ((long)(32)) */
  86. FE_OVERFLOW = 0x00000040, /* ((long)(64)) */
  87. FE_INVALID = 0x00000080, /* ((long)(128)) */
  88. FE_ALL_EXCEPT = 0x000000F8 /* FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID*/
  89. };
  90. #else
  91. typedef short fexcept_t;
  92. typedef short fenv_t;
  93. enum {
  94. FE_INVALID = 0x0001, /* ((short)(1)) */
  95. FE_UNDERFLOW = 0x0002, /* ((short)(2)) */
  96. FE_OVERFLOW = 0x0004, /* ((short)(4)) */
  97. FE_DIVBYZERO = 0x0008, /* ((short)(8)) */
  98. FE_INEXACT = 0x0010, /* ((short)(16)) */
  99. FE_ALL_EXCEPT = 0x001F /* FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID*/
  100. };
  101. #endif /* TARGET_RT_MAC_68881 */
  102. enum {
  103. FE_TONEAREST = 0x0000, /* ((short)(0)) */
  104. FE_UPWARD = 0x0001, /* ((short)(1)) */
  105. FE_DOWNWARD = 0x0002, /* ((short)(2)) */
  106. FE_TOWARDZERO = 0x0003 /* ((short)(3)) */
  107. };
  108. /* Definitions of rounding precision macros (68K only) */
  109. enum {
  110. FE_LDBLPREC = 0x0000, /* ((short)(0)) */
  111. FE_DBLPREC = 0x0001, /* ((short)(1)) */
  112. FE_FLTPREC = 0x0002 /* ((short)(2)) */
  113. };
  114. #endif /* TARGET_CPU_68K */
  115. /* default environment object */
  116. /*
  117. * _FE_DFL_ENV
  118. *
  119. * Availability:
  120. * Non-Carbon CFM: in MathLib 1.0 and later
  121. * CarbonLib: in CarbonLib 1.3 and later
  122. * Mac OS X: in version 10.1 and later
  123. */
  124. extern fenv_t _FE_DFL_ENV;
  125. #define FE_DFL_ENV &_FE_DFL_ENV /* pointer to default environment */
  126. /*******************************************************************************
  127. * The following functions provide access to the exception flags. The *
  128. * "int" input argument can be constructed by bitwise ORs of the exception *
  129. * macros: for example: FE_OVERFLOW | FE_INEXACT. *
  130. *******************************************************************************/
  131. /*******************************************************************************
  132. * The function "feclearexcept" clears the supported exceptions represented *
  133. * by its argument. *
  134. *******************************************************************************/
  135. /*
  136. * feclearexcept()
  137. *
  138. * Availability:
  139. * Non-Carbon CFM: in MathLib 1.0 and later
  140. * CarbonLib: in CarbonLib 1.0 and later
  141. * Mac OS X: in version 10.0 and later
  142. */
  143. EXTERN_API_C( void ) feclearexcept(int excepts);
  144. /*******************************************************************************
  145. * The function "fegetexcept" stores a representation of the exception *
  146. * flags indicated by the argument "excepts" through the pointer argument *
  147. * "flagp". *
  148. *******************************************************************************/
  149. /*
  150. * fegetexcept()
  151. *
  152. * Availability:
  153. * Non-Carbon CFM: in MathLib 1.0 and later
  154. * CarbonLib: in CarbonLib 1.0 and later
  155. * Mac OS X: in version 10.0 and later
  156. */
  157. EXTERN_API_C( void ) fegetexcept(fexcept_t *flagp, int excepts);
  158. /*******************************************************************************
  159. * The function "feraiseexcept" raises the supported exceptions *
  160. * represented by its argument. *
  161. *******************************************************************************/
  162. /*
  163. * feraiseexcept()
  164. *
  165. * Availability:
  166. * Non-Carbon CFM: in MathLib 1.0 and later
  167. * CarbonLib: in CarbonLib 1.0 and later
  168. * Mac OS X: in version 10.0 and later
  169. */
  170. EXTERN_API_C( void ) feraiseexcept(int excepts);
  171. /*******************************************************************************
  172. * The function "fesetexcept" sets or clears the exception flags indicated *
  173. * by the int argument "excepts" according to the representation in the *
  174. * object pointed to by the pointer argument "flagp". The value of *
  175. * "*flagp" must have been set by a previous call to "fegetexcept". *
  176. * This function does not raise exceptions; it just sets the state of *
  177. * the flags. *
  178. *******************************************************************************/
  179. /*
  180. * fesetexcept()
  181. *
  182. * Availability:
  183. * Non-Carbon CFM: in MathLib 1.0 and later
  184. * CarbonLib: in CarbonLib 1.0 and later
  185. * Mac OS X: in version 10.0 and later
  186. */
  187. EXTERN_API_C( void ) fesetexcept(const fexcept_t *flagp, int excepts);
  188. /*******************************************************************************
  189. * The function "fetestexcept" determines which of the specified subset of *
  190. * the exception flags are currently set. The argument "excepts" specifies *
  191. * the exception flags to be queried as a bitwise OR of the exception *
  192. * macros. This function returns the bitwise OR of the exception macros *
  193. * corresponding to the currently set exceptions included in "excepts". *
  194. *******************************************************************************/
  195. /*
  196. * fetestexcept()
  197. *
  198. * Availability:
  199. * Non-Carbon CFM: in MathLib 1.0 and later
  200. * CarbonLib: in CarbonLib 1.0 and later
  201. * Mac OS X: in version 10.0 and later
  202. */
  203. EXTERN_API_C( int ) fetestexcept(int excepts);
  204. /*******************************************************************************
  205. * The following functions provide control of rounding direction modes. *
  206. *******************************************************************************/
  207. /*******************************************************************************
  208. * The function "fegetround" returns the value of the rounding direction *
  209. * macro which represents the current rounding direction. *
  210. *******************************************************************************/
  211. /*
  212. * fegetround()
  213. *
  214. * Availability:
  215. * Non-Carbon CFM: in MathLib 1.0 and later
  216. * CarbonLib: in CarbonLib 1.0 and later
  217. * Mac OS X: in version 10.0 and later
  218. */
  219. EXTERN_API_C( int ) fegetround(void);
  220. /*******************************************************************************
  221. * The function "fesetround" establishes the rounding direction represented *
  222. * by its argument. It returns nonzero if and only if the argument matches *
  223. * a rounding direction macro. If not, the rounding direction is not *
  224. * changed. *
  225. *******************************************************************************/
  226. /*
  227. * fesetround()
  228. *
  229. * Availability:
  230. * Non-Carbon CFM: in MathLib 1.0 and later
  231. * CarbonLib: in CarbonLib 1.0 and later
  232. * Mac OS X: in version 10.0 and later
  233. */
  234. EXTERN_API_C( int ) fesetround(int round);
  235. /*******************************************************************************
  236. * The following functions manage the floating-point environment, exception *
  237. * flags and dynamic modes, as one entity. *
  238. *******************************************************************************/
  239. /*******************************************************************************
  240. * The function "fegetenv" stores the current floating-point environment *
  241. * in the object pointed to by its pointer argument "envp". *
  242. *******************************************************************************/
  243. /*
  244. * fegetenv()
  245. *
  246. * Availability:
  247. * Non-Carbon CFM: in MathLib 1.0 and later
  248. * CarbonLib: in CarbonLib 1.0 and later
  249. * Mac OS X: in version 10.0 and later
  250. */
  251. EXTERN_API_C( void ) fegetenv(fenv_t * envp);
  252. /*******************************************************************************
  253. * The function "feholdexcept" saves the current environment in the object *
  254. * pointed to by its pointer argument "envp", clears the exception flags, *
  255. * and clears floating-point exception enables. This function supersedes *
  256. * the SANE function "procentry", but it does not change the current *
  257. * rounding direction mode. *
  258. *******************************************************************************/
  259. /*
  260. * feholdexcept()
  261. *
  262. * Availability:
  263. * Non-Carbon CFM: in MathLib 1.0 and later
  264. * CarbonLib: in CarbonLib 1.0 and later
  265. * Mac OS X: in version 10.0 and later
  266. */
  267. EXTERN_API_C( int ) feholdexcept(fenv_t * envp);
  268. /*******************************************************************************
  269. * The function "fesetenv" installs the floating-point environment *
  270. * environment represented by the object pointed to by its argument *
  271. * "envp". The value of "*envp" must be set by a call to "fegetenv" or *
  272. * "feholdexcept", by an implementation-defined macro of type "fenv_t", *
  273. * or by the use of the pointer macro FE_DFL_ENV as the argument. *
  274. *******************************************************************************/
  275. /*
  276. * fesetenv()
  277. *
  278. * Availability:
  279. * Non-Carbon CFM: in MathLib 1.0 and later
  280. * CarbonLib: in CarbonLib 1.0 and later
  281. * Mac OS X: in version 10.0 and later
  282. */
  283. EXTERN_API_C( void ) fesetenv(const fenv_t * envp);
  284. /*******************************************************************************
  285. * The function "feupdateenv" saves the current exceptions into its *
  286. * automatic storage, installs the environment represented through its *
  287. * pointer argument "envp", and then re-raises the saved exceptions. *
  288. * This function, which supersedes the SANE function "procexit", can be *
  289. * used in conjunction with "feholdexcept" to write routines which hide *
  290. * spurious exceptions from their callers. *
  291. *******************************************************************************/
  292. /*
  293. * feupdateenv()
  294. *
  295. * Availability:
  296. * Non-Carbon CFM: in MathLib 1.0 and later
  297. * CarbonLib: in CarbonLib 1.0 and later
  298. * Mac OS X: in version 10.0 and later
  299. */
  300. EXTERN_API_C( void ) feupdateenv(const fenv_t * envp);
  301. #if TARGET_CPU_68K
  302. /*******************************************************************************
  303. * The following functions provide control of rounding precision. *
  304. * Because the PowerPC does not provide this capability, these functions *
  305. * are available only for the 68K Macintosh. Rounding precision values *
  306. * are defined by the rounding precision macros. These functions are *
  307. * equivalent to the SANE functions getprecision and setprecision. *
  308. *******************************************************************************/
  309. #if CALL_NOT_IN_CARBON
  310. /*
  311. * fegetprec()
  312. *
  313. * Availability:
  314. * Non-Carbon CFM: not available
  315. * CarbonLib: not available
  316. * Mac OS X: not available
  317. */
  318. EXTERN_API_C( int ) fegetprec(void);
  319. /*
  320. * fesetprec()
  321. *
  322. * Availability:
  323. * Non-Carbon CFM: not available
  324. * CarbonLib: not available
  325. * Mac OS X: not available
  326. */
  327. EXTERN_API_C( int ) fesetprec(int precision);
  328. #endif /* CALL_NOT_IN_CARBON */
  329. #endif /* TARGET_CPU_68K */
  330. #endif /* TARGET_OS_MAC */
  331. #endif /* TARGET_RT_MAC_MACHO && defined(__MATH__) */
  332. #if PRAGMA_STRUCT_ALIGN
  333. #pragma options align=reset
  334. #elif PRAGMA_STRUCT_PACKPUSH
  335. #pragma pack(pop)
  336. #elif PRAGMA_STRUCT_PACK
  337. #pragma pack()
  338. #endif
  339. #ifdef PRAGMA_IMPORT_OFF
  340. #pragma import off
  341. #elif PRAGMA_IMPORT
  342. #pragma import reset
  343. #endif
  344. #ifdef __cplusplus
  345. }
  346. #endif
  347. #endif /* __FENV__ */