fenv.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 308
  26. Please report any bugs to <[email protected]>
  27. }
  28. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  29. {$mode macpas}
  30. {$modeswitch cblocks}
  31. {$packenum 1}
  32. {$macro on}
  33. {$inline on}
  34. {$calling mwpascal}
  35. {$IFNDEF FPC_DOTTEDUNITS}
  36. unit fenv;
  37. {$ENDIF FPC_DOTTEDUNITS}
  38. interface
  39. {$setc UNIVERSAL_INTERFACES_VERSION := $0400}
  40. {$setc GAP_INTERFACES_VERSION := $0308}
  41. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  42. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  43. {$endc}
  44. {$ifc defined CPUPOWERPC and defined CPUI386}
  45. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  46. {$endc}
  47. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  48. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  49. {$endc}
  50. {$ifc not defined __ppc__ and defined CPUPOWERPC32}
  51. {$setc __ppc__ := 1}
  52. {$elsec}
  53. {$setc __ppc__ := 0}
  54. {$endc}
  55. {$ifc not defined __ppc64__ and defined CPUPOWERPC64}
  56. {$setc __ppc64__ := 1}
  57. {$elsec}
  58. {$setc __ppc64__ := 0}
  59. {$endc}
  60. {$ifc not defined __i386__ and defined CPUI386}
  61. {$setc __i386__ := 1}
  62. {$elsec}
  63. {$setc __i386__ := 0}
  64. {$endc}
  65. {$ifc not defined __x86_64__ and defined CPUX86_64}
  66. {$setc __x86_64__ := 1}
  67. {$elsec}
  68. {$setc __x86_64__ := 0}
  69. {$endc}
  70. {$ifc not defined __arm__ and defined CPUARM}
  71. {$setc __arm__ := 1}
  72. {$elsec}
  73. {$setc __arm__ := 0}
  74. {$endc}
  75. {$ifc not defined __arm64__ and defined CPUAARCH64}
  76. {$setc __arm64__ := 1}
  77. {$elsec}
  78. {$setc __arm64__ := 0}
  79. {$endc}
  80. {$ifc defined cpu64}
  81. {$setc __LP64__ := 1}
  82. {$elsec}
  83. {$setc __LP64__ := 0}
  84. {$endc}
  85. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  86. {$error Conflicting definitions for __ppc__ and __i386__}
  87. {$endc}
  88. {$ifc defined __ppc__ and __ppc__}
  89. {$setc TARGET_CPU_PPC := TRUE}
  90. {$setc TARGET_CPU_PPC64 := FALSE}
  91. {$setc TARGET_CPU_X86 := FALSE}
  92. {$setc TARGET_CPU_X86_64 := FALSE}
  93. {$setc TARGET_CPU_ARM := FALSE}
  94. {$setc TARGET_CPU_ARM64 := FALSE}
  95. {$setc TARGET_OS_MAC := TRUE}
  96. {$setc TARGET_OS_IPHONE := FALSE}
  97. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  98. {$setc TARGET_OS_EMBEDDED := FALSE}
  99. {$elifc defined __ppc64__ and __ppc64__}
  100. {$setc TARGET_CPU_PPC := FALSE}
  101. {$setc TARGET_CPU_PPC64 := TRUE}
  102. {$setc TARGET_CPU_X86 := FALSE}
  103. {$setc TARGET_CPU_X86_64 := FALSE}
  104. {$setc TARGET_CPU_ARM := FALSE}
  105. {$setc TARGET_CPU_ARM64 := FALSE}
  106. {$setc TARGET_OS_MAC := TRUE}
  107. {$setc TARGET_OS_IPHONE := FALSE}
  108. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  109. {$setc TARGET_OS_EMBEDDED := FALSE}
  110. {$elifc defined __i386__ and __i386__}
  111. {$setc TARGET_CPU_PPC := FALSE}
  112. {$setc TARGET_CPU_PPC64 := FALSE}
  113. {$setc TARGET_CPU_X86 := TRUE}
  114. {$setc TARGET_CPU_X86_64 := FALSE}
  115. {$setc TARGET_CPU_ARM := FALSE}
  116. {$setc TARGET_CPU_ARM64 := FALSE}
  117. {$ifc defined iphonesim}
  118. {$setc TARGET_OS_MAC := FALSE}
  119. {$setc TARGET_OS_IPHONE := TRUE}
  120. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  121. {$elsec}
  122. {$setc TARGET_OS_MAC := TRUE}
  123. {$setc TARGET_OS_IPHONE := FALSE}
  124. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  125. {$endc}
  126. {$setc TARGET_OS_EMBEDDED := FALSE}
  127. {$elifc defined __x86_64__ and __x86_64__}
  128. {$setc TARGET_CPU_PPC := FALSE}
  129. {$setc TARGET_CPU_PPC64 := FALSE}
  130. {$setc TARGET_CPU_X86 := FALSE}
  131. {$setc TARGET_CPU_X86_64 := TRUE}
  132. {$setc TARGET_CPU_ARM := FALSE}
  133. {$setc TARGET_CPU_ARM64 := FALSE}
  134. {$ifc defined iphonesim}
  135. {$setc TARGET_OS_MAC := FALSE}
  136. {$setc TARGET_OS_IPHONE := TRUE}
  137. {$setc TARGET_IPHONE_SIMULATOR := TRUE}
  138. {$elsec}
  139. {$setc TARGET_OS_MAC := TRUE}
  140. {$setc TARGET_OS_IPHONE := FALSE}
  141. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  142. {$endc}
  143. {$setc TARGET_OS_EMBEDDED := FALSE}
  144. {$elifc defined __arm__ and __arm__}
  145. {$setc TARGET_CPU_PPC := FALSE}
  146. {$setc TARGET_CPU_PPC64 := FALSE}
  147. {$setc TARGET_CPU_X86 := FALSE}
  148. {$setc TARGET_CPU_X86_64 := FALSE}
  149. {$setc TARGET_CPU_ARM := TRUE}
  150. {$setc TARGET_CPU_ARM64 := FALSE}
  151. {$setc TARGET_OS_MAC := FALSE}
  152. {$setc TARGET_OS_IPHONE := TRUE}
  153. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  154. {$setc TARGET_OS_EMBEDDED := TRUE}
  155. {$elifc defined __arm64__ and __arm64__}
  156. {$setc TARGET_CPU_PPC := FALSE}
  157. {$setc TARGET_CPU_PPC64 := FALSE}
  158. {$setc TARGET_CPU_X86 := FALSE}
  159. {$setc TARGET_CPU_X86_64 := FALSE}
  160. {$setc TARGET_CPU_ARM := FALSE}
  161. {$setc TARGET_CPU_ARM64 := TRUE}
  162. {$ifc defined ios}
  163. {$setc TARGET_OS_MAC := FALSE}
  164. {$setc TARGET_OS_IPHONE := TRUE}
  165. {$setc TARGET_OS_EMBEDDED := TRUE}
  166. {$elsec}
  167. {$setc TARGET_OS_MAC := TRUE}
  168. {$setc TARGET_OS_IPHONE := FALSE}
  169. {$setc TARGET_OS_EMBEDDED := FALSE}
  170. {$endc}
  171. {$setc TARGET_IPHONE_SIMULATOR := FALSE}
  172. {$elsec}
  173. {$error __ppc__ nor __ppc64__ nor __i386__ nor __x86_64__ nor __arm__ nor __arm64__ is defined.}
  174. {$endc}
  175. {$ifc defined __LP64__ and __LP64__ }
  176. {$setc TARGET_CPU_64 := TRUE}
  177. {$elsec}
  178. {$setc TARGET_CPU_64 := FALSE}
  179. {$endc}
  180. {$ifc defined FPC_BIG_ENDIAN}
  181. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  182. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  183. {$elifc defined FPC_LITTLE_ENDIAN}
  184. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  185. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  186. {$elsec}
  187. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  188. {$endc}
  189. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  190. {$setc CALL_NOT_IN_CARBON := FALSE}
  191. {$setc OLDROUTINENAMES := FALSE}
  192. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  193. {$setc OPAQUE_UPP_TYPES := TRUE}
  194. {$setc OTCARBONAPPLICATION := TRUE}
  195. {$setc OTKERNEL := FALSE}
  196. {$setc PM_USE_SESSION_APIS := TRUE}
  197. {$setc TARGET_API_MAC_CARBON := TRUE}
  198. {$setc TARGET_API_MAC_OS8 := FALSE}
  199. {$setc TARGET_API_MAC_OSX := TRUE}
  200. {$setc TARGET_CARBON := TRUE}
  201. {$setc TARGET_CPU_68K := FALSE}
  202. {$setc TARGET_CPU_MIPS := FALSE}
  203. {$setc TARGET_CPU_SPARC := FALSE}
  204. {$setc TARGET_OS_UNIX := FALSE}
  205. {$setc TARGET_OS_WIN32 := FALSE}
  206. {$setc TARGET_RT_MAC_68881 := FALSE}
  207. {$setc TARGET_RT_MAC_CFM := FALSE}
  208. {$setc TARGET_RT_MAC_MACHO := TRUE}
  209. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  210. {$setc TYPE_BOOL := FALSE}
  211. {$setc TYPE_EXTENDED := FALSE}
  212. {$setc TYPE_LONGLONG := TRUE}
  213. {$IFDEF FPC_DOTTEDUNITS}
  214. uses MacOsApi.MacTypes;
  215. {$ELSE FPC_DOTTEDUNITS}
  216. uses MacTypes;
  217. {$ENDIF FPC_DOTTEDUNITS}
  218. {$endc} {not MACOSALLINCLUDE}
  219. {$ifc TARGET_OS_MAC}
  220. {$ALIGN POWER}
  221. {******************************************************************************
  222. * *
  223. * File: fenv.h *
  224. * *
  225. * Contains: typedefs and prototypes for C99 floating point environment. *
  226. * *
  227. ******************************************************************************}
  228. {
  229. A collection of functions designed to provide access to the floating
  230. point environment for numerical programming. It is modeled after
  231. the floating-point requirements in C9X.
  232. The file <fenv.h> declares many functions in support of numerical
  233. programming. Programs that test flags or run under
  234. non-default modes must do so under the effect of an enabling
  235. "fenv_access" pragma.
  236. }
  237. {*******************************************************************************
  238. * *
  239. * fenv_t is a type for representing the entire floating-point *
  240. * environment in a single object. *
  241. * *
  242. * fexcept_t is a type for representing the floating-point *
  243. * exception flag state collectively. *
  244. * *
  245. *******************************************************************************}
  246. {$ifc TARGET_CPU_PPC}
  247. type
  248. fenv_t = UInt32;
  249. fexcept_t = UInt32;
  250. {$elsec}
  251. type
  252. fenv_t = record
  253. __control: UInt16;
  254. __status: UInt16;
  255. end;
  256. fexcept_t = UInt16;
  257. {$endc}
  258. { Definitions of floating-point exception macros }
  259. {$ifc TARGET_CPU_PPC}
  260. const
  261. _FE_INEXACT = $02000000;
  262. _FE_DIVBYZERO = $04000000;
  263. _FE_UNDERFLOW = $08000000;
  264. _FE_OVERFLOW = $10000000;
  265. _FE_INVALID = $20000000;
  266. _FE_ALL_EXCEPT = $3E000000; // FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID
  267. {$elsec}
  268. const
  269. _FE_INEXACT = $0020;
  270. _FE_DIVBYZERO = $0004;
  271. _FE_UNDERFLOW = $0010;
  272. _FE_OVERFLOW = $0008;
  273. _FE_INVALID = $0001;
  274. _FE_ALL_EXCEPT = $003D; // FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID
  275. {$endc}
  276. const
  277. FE_INEXACT = _FE_INEXACT;
  278. FE_DIVBYZERO = _FE_DIVBYZERO;
  279. FE_UNDERFLOW = _FE_UNDERFLOW;
  280. FE_OVERFLOW = _FE_OVERFLOW;
  281. FE_INVALID = _FE_INVALID;
  282. FE_ALL_EXCEPT = _FE_ALL_EXCEPT;
  283. { Definitions of rounding direction macros }
  284. {$ifc TARGET_CPU_PPC}
  285. const
  286. _FE_TONEAREST = $00000000;
  287. _FE_TOWARDZERO = $00000001;
  288. _FE_UPWARD = $00000002;
  289. _FE_DOWNWARD = $00000003;
  290. {$elsec}
  291. const
  292. _FE_TONEAREST = $0000;
  293. _FE_TOWARDZERO = $0C00;
  294. _FE_UPWARD = $0800;
  295. _FE_DOWNWARD = $0400;
  296. {$endc}
  297. const
  298. FE_TONEAREST = _FE_TONEAREST;
  299. FE_TOWARDZERO = _FE_TOWARDZERO;
  300. FE_UPWARD = _FE_UPWARD;
  301. FE_DOWNWARD = _FE_DOWNWARD;
  302. { default environment object }
  303. var _FE_DFL_ENV: fenv_t; external name '__FE_DFL_ENV'; (* attribute const *)
  304. // #define FE_DFL_ENV &_FE_DFL_ENV { pointer to default environment }
  305. {******************************************************************************
  306. * The following functions provide access to the exception flags. The *
  307. * "int" input argument can be constructed by bitwise ORs of the exception *
  308. * macros: for example: FE_OVERFLOW | FE_INEXACT. *
  309. ******************************************************************************}
  310. {******************************************************************************
  311. * The function "feclearexcept" clears the supported exceptions represented *
  312. * by its argument. *
  313. ******************************************************************************}
  314. function feclearexcept( excepts: SInt32 ): SInt32; external name '_feclearexcept';
  315. {******************************************************************************
  316. * The function "fegetexceptflag" stores a representation of the exception *
  317. * flags indicated by its integer argument through the fexcept_t pointer *
  318. * argument. *
  319. ******************************************************************************}
  320. function fegetexceptflag( var flagp: fexcept_t; excepts: SInt32 ): SInt32; external name '_fegetexceptflag';
  321. {******************************************************************************
  322. * The function "feraiseexcept" raises the supported exceptions *
  323. * represented by its argument. *
  324. ******************************************************************************}
  325. function feraiseexcept( excepts: SInt32 ): SInt32; external name '_feraiseexcept';
  326. {******************************************************************************
  327. * The function "fesetexceptflag" sets or clears the exception flags indicated *
  328. * by the its integer argument according to the representation in the *
  329. * object pointed to by the fexcept_t pointer argument. The value of the *
  330. * object must have been set by a previous call to "fegetexceptflag". *
  331. * This function does not raise exceptions; it just sets the state of *
  332. * the flags. *
  333. ******************************************************************************}
  334. function fesetexceptflag( (*const*) var flagp: fexcept_t; excepts: SInt32 ): SInt32; external name '_fesetexceptflag';
  335. {******************************************************************************
  336. * The function "fetestexcept" determines which of the specified subset of *
  337. * the exception flags are currently set. The integer argument specifies *
  338. * the exception flags to be queried as a bitwise OR of the exception *
  339. * macros. This function returns the bitwise OR of the exception macros *
  340. * corresponding to the currently set exceptions included in "excepts". *
  341. ******************************************************************************}
  342. function fetestexcept( excepts: SInt32 ): SInt32; external name '_fetestexcept';
  343. {******************************************************************************
  344. * The following functions provide control of rounding direction modes. *
  345. ******************************************************************************}
  346. {******************************************************************************
  347. * The function "fegetround" returns the value of the rounding direction *
  348. * macro which represents the current rounding direction. *
  349. ******************************************************************************}
  350. function fegetround: SInt32; external name '_fegetround';
  351. {******************************************************************************
  352. * The function "fesetround" establishes the rounding direction represented *
  353. * by its argument. It returns zero if and only if the argument matches *
  354. * a rounding direction macro. If not, the rounding direction is not *
  355. * changed. *
  356. ******************************************************************************}
  357. function fesetround( round: SInt32 ): SInt32; external name '_fesetround';
  358. {******************************************************************************
  359. * The following functions manage the floating-point environment, exception *
  360. * flags and dynamic modes, as one entity. *
  361. ******************************************************************************}
  362. function fegetenv( var envp: fenv_t ): SInt32; external name '_fegetenv';
  363. function feholdexcept( var envp: fenv_t ): SInt32; external name '_feholdexcept';
  364. function fesetenv( (*const*) var envp: fenv_t ): SInt32; external name '_fesetenv';
  365. function feupdateenv( (*const*) var envp: fenv_t ): SInt32; external name '_feupdateenv';
  366. {$endc} {TARGET_OS_MAC}
  367. {$ifc not defined MACOSALLINCLUDE or not MACOSALLINCLUDE}
  368. end.
  369. {$endc} {not MACOSALLINCLUDE}