fenv.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. {
  2. * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
  3. *
  4. * @APPLE_LICENSE_HEADER_START@
  5. *
  6. * The contents of this file constitute Original Code as defined in and
  7. * are subject to the Apple Public Source License Version 1.1 (the
  8. * "License"). You may not use this file except in compliance with the
  9. * License. Please obtain a copy of the License at
  10. * http://www.apple.com/publicsource and read it before using this file.
  11. *
  12. * This Original Code and all software distributed under the License are
  13. * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14. * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15. * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
  17. * License for the specific language governing rights and limitations
  18. * under the License.
  19. *
  20. * @APPLE_LICENSE_HEADER_END@
  21. }
  22. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, November 2005 }
  23. {
  24. Modified for use with Free Pascal
  25. Version 200
  26. Please report any bugs to <[email protected]>
  27. }
  28. {$mode macpas}
  29. {$packenum 1}
  30. {$macro on}
  31. {$inline on}
  32. {$CALLING MWPASCAL}
  33. unit fenv;
  34. interface
  35. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  36. {$setc GAP_INTERFACES_VERSION := $0200}
  37. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  38. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  39. {$endc}
  40. {$ifc defined CPUPOWERPC and defined CPUI386}
  41. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  42. {$endc}
  43. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  44. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  45. {$endc}
  46. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  47. {$setc __ppc__ := 1}
  48. {$elsec}
  49. {$setc __ppc__ := 0}
  50. {$endc}
  51. {$ifc not defined __i386__ and defined CPUI386}
  52. {$setc __i386__ := 1}
  53. {$elsec}
  54. {$setc __i386__ := 0}
  55. {$endc}
  56. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  57. {$error Conflicting definitions for __ppc__ and __i386__}
  58. {$endc}
  59. {$ifc defined __ppc__ and __ppc__}
  60. {$setc TARGET_CPU_PPC := TRUE}
  61. {$setc TARGET_CPU_X86 := FALSE}
  62. {$elifc defined __i386__ and __i386__}
  63. {$setc TARGET_CPU_PPC := FALSE}
  64. {$setc TARGET_CPU_X86 := TRUE}
  65. {$elsec}
  66. {$error Neither __ppc__ nor __i386__ is defined.}
  67. {$endc}
  68. {$setc TARGET_CPU_PPC_64 := FALSE}
  69. {$ifc defined FPC_BIG_ENDIAN}
  70. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  71. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  72. {$elifc defined FPC_LITTLE_ENDIAN}
  73. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  74. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  75. {$elsec}
  76. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  77. {$endc}
  78. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  79. {$setc CALL_NOT_IN_CARBON := FALSE}
  80. {$setc OLDROUTINENAMES := FALSE}
  81. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  82. {$setc OPAQUE_UPP_TYPES := TRUE}
  83. {$setc OTCARBONAPPLICATION := TRUE}
  84. {$setc OTKERNEL := FALSE}
  85. {$setc PM_USE_SESSION_APIS := TRUE}
  86. {$setc TARGET_API_MAC_CARBON := TRUE}
  87. {$setc TARGET_API_MAC_OS8 := FALSE}
  88. {$setc TARGET_API_MAC_OSX := TRUE}
  89. {$setc TARGET_CARBON := TRUE}
  90. {$setc TARGET_CPU_68K := FALSE}
  91. {$setc TARGET_CPU_MIPS := FALSE}
  92. {$setc TARGET_CPU_SPARC := FALSE}
  93. {$setc TARGET_OS_MAC := TRUE}
  94. {$setc TARGET_OS_UNIX := FALSE}
  95. {$setc TARGET_OS_WIN32 := FALSE}
  96. {$setc TARGET_RT_MAC_68881 := FALSE}
  97. {$setc TARGET_RT_MAC_CFM := FALSE}
  98. {$setc TARGET_RT_MAC_MACHO := TRUE}
  99. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  100. {$setc TYPE_BOOL := FALSE}
  101. {$setc TYPE_EXTENDED := FALSE}
  102. {$setc TYPE_LONGLONG := TRUE}
  103. uses MacTypes;
  104. {$ALIGN POWER}
  105. {******************************************************************************
  106. * *
  107. * File: fenv.h *
  108. * *
  109. * Contains: typedefs and prototypes for C99 floating point environment. *
  110. * *
  111. ******************************************************************************}
  112. {
  113. A collection of functions designed to provide access to the floating
  114. point environment for numerical programming. It is modeled after
  115. the floating-point requirements in C9X.
  116. The file <fenv.h> declares many functions in support of numerical
  117. programming. Programs that test flags or run under
  118. non-default modes must do so under the effect of an enabling
  119. "fenv_access" pragma.
  120. }
  121. {*******************************************************************************
  122. * *
  123. * fenv_t is a type for representing the entire floating-point *
  124. * environment in a single object. *
  125. * *
  126. * fexcept_t is a type for representing the floating-point *
  127. * exception flag state collectively. *
  128. * *
  129. *******************************************************************************}
  130. {$ifc TARGET_CPU_PPC}
  131. type
  132. fenv_t = UInt32;
  133. fexcept_t = UInt32;
  134. {$elsec}
  135. type
  136. fenv_t = record
  137. __control: UInt16;
  138. __status: UInt16;
  139. end;
  140. fexcept_t = UInt16;
  141. {$endc}
  142. { Definitions of floating-point exception macros }
  143. {$ifc TARGET_CPU_PPC}
  144. const
  145. _FE_INEXACT = $02000000;
  146. _FE_DIVBYZERO = $04000000;
  147. _FE_UNDERFLOW = $08000000;
  148. _FE_OVERFLOW = $10000000;
  149. _FE_INVALID = $20000000;
  150. _FE_ALL_EXCEPT = $3E000000; // FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID
  151. {$elsec}
  152. const
  153. _FE_INEXACT = $0020;
  154. _FE_DIVBYZERO = $0004;
  155. _FE_UNDERFLOW = $0010;
  156. _FE_OVERFLOW = $0008;
  157. _FE_INVALID = $0001;
  158. _FE_ALL_EXCEPT = $003D; // FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID
  159. {$endc}
  160. const
  161. FE_INEXACT = _FE_INEXACT;
  162. FE_DIVBYZERO = _FE_DIVBYZERO;
  163. FE_UNDERFLOW = _FE_UNDERFLOW;
  164. FE_OVERFLOW = _FE_OVERFLOW;
  165. FE_INVALID = _FE_INVALID;
  166. FE_ALL_EXCEPT = _FE_ALL_EXCEPT;
  167. { Definitions of rounding direction macros }
  168. {$ifc TARGET_CPU_PPC}
  169. const
  170. _FE_TONEAREST = $00000000;
  171. _FE_TOWARDZERO = $00000001;
  172. _FE_UPWARD = $00000002;
  173. _FE_DOWNWARD = $00000003;
  174. {$elsec}
  175. const
  176. _FE_TONEAREST = $0000;
  177. _FE_TOWARDZERO = $0C00;
  178. _FE_UPWARD = $0800;
  179. _FE_DOWNWARD = $0400;
  180. {$endc}
  181. const
  182. FE_TONEAREST = _FE_TONEAREST;
  183. FE_TOWARDZERO = _FE_TOWARDZERO;
  184. FE_UPWARD = _FE_UPWARD;
  185. FE_DOWNWARD = _FE_DOWNWARD;
  186. { default environment object }
  187. var _FE_DFL_ENV: fenv_t; external name '__FE_DFL_ENV'; (* attribute const *)
  188. // #define FE_DFL_ENV &_FE_DFL_ENV { pointer to default environment }
  189. {******************************************************************************
  190. * The following functions provide access to the exception flags. The *
  191. * "int" input argument can be constructed by bitwise ORs of the exception *
  192. * macros: for example: FE_OVERFLOW | FE_INEXACT. *
  193. ******************************************************************************}
  194. {******************************************************************************
  195. * The function "feclearexcept" clears the supported exceptions represented *
  196. * by its argument. *
  197. ******************************************************************************}
  198. function feclearexcept( excepts: SInt32 ): SInt32; external name '_feclearexcept';
  199. {******************************************************************************
  200. * The function "fegetexceptflag" stores a representation of the exception *
  201. * flags indicated by its integer argument through the fexcept_t pointer *
  202. * argument. *
  203. ******************************************************************************}
  204. function fegetexceptflag( var flagp: fexcept_t; excepts: SInt32 ): SInt32; external name '_fegetexceptflag';
  205. {******************************************************************************
  206. * The function "feraiseexcept" raises the supported exceptions *
  207. * represented by its argument. *
  208. ******************************************************************************}
  209. function feraiseexcept( excepts: SInt32 ): SInt32; external name '_feraiseexcept';
  210. {******************************************************************************
  211. * The function "fesetexceptflag" sets or clears the exception flags indicated *
  212. * by the its integer argument according to the representation in the *
  213. * object pointed to by the fexcept_t pointer argument. The value of the *
  214. * object must have been set by a previous call to "fegetexceptflag". *
  215. * This function does not raise exceptions; it just sets the state of *
  216. * the flags. *
  217. ******************************************************************************}
  218. function fesetexceptflag( (*const*) var flagp: fexcept_t; excepts: SInt32 ): SInt32; external name '_fesetexceptflag';
  219. {******************************************************************************
  220. * The function "fetestexcept" determines which of the specified subset of *
  221. * the exception flags are currently set. The integer argument specifies *
  222. * the exception flags to be queried as a bitwise OR of the exception *
  223. * macros. This function returns the bitwise OR of the exception macros *
  224. * corresponding to the currently set exceptions included in "excepts". *
  225. ******************************************************************************}
  226. function fetestexcept( excepts: SInt32 ): SInt32; external name '_fetestexcept';
  227. {******************************************************************************
  228. * The following functions provide control of rounding direction modes. *
  229. ******************************************************************************}
  230. {******************************************************************************
  231. * The function "fegetround" returns the value of the rounding direction *
  232. * macro which represents the current rounding direction. *
  233. ******************************************************************************}
  234. function fegetround: SInt32; external name '_fegetround';
  235. {******************************************************************************
  236. * The function "fesetround" establishes the rounding direction represented *
  237. * by its argument. It returns zero if and only if the argument matches *
  238. * a rounding direction macro. If not, the rounding direction is not *
  239. * changed. *
  240. ******************************************************************************}
  241. function fesetround( round: SInt32 ): SInt32; external name '_fesetround';
  242. {******************************************************************************
  243. * The following functions manage the floating-point environment, exception *
  244. * flags and dynamic modes, as one entity. *
  245. ******************************************************************************}
  246. function fegetenv( var envp: fenv_t ): SInt32; external name '_fegetenv';
  247. function feholdexcept( var envp: fenv_t ): SInt32; external name '_feholdexcept';
  248. function fesetenv( (*const*) var envp: fenv_t ): SInt32; external name '_fesetenv';
  249. function feupdateenv( (*const*) var envp: fenv_t ): SInt32; external name '_feupdateenv';
  250. end.