FixMath.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. {
  2. File: FixMath.p
  3. Contains: Fixed Math Interfaces.
  4. Version: Technology: Mac OS 8
  5. Release: Universal Interfaces 3.4.2
  6. Copyright: © 1985-2002 by Apple Computer, Inc., all rights reserved
  7. Bugs?: For bug reports, consult the following page on
  8. the World Wide Web:
  9. http://www.freepascal.org/bugs.html
  10. }
  11. {
  12. Modified for use with Free Pascal
  13. Version 200
  14. Please report any bugs to <[email protected]>
  15. }
  16. {$mode macpas}
  17. {$packenum 1}
  18. {$macro on}
  19. {$inline on}
  20. {$CALLING MWPASCAL}
  21. unit FixMath;
  22. interface
  23. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  24. {$setc GAP_INTERFACES_VERSION := $0200}
  25. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  26. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  27. {$endc}
  28. {$ifc defined CPUPOWERPC and defined CPUI386}
  29. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  30. {$endc}
  31. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  32. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  33. {$endc}
  34. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  35. {$setc __ppc__ := 1}
  36. {$elsec}
  37. {$setc __ppc__ := 0}
  38. {$endc}
  39. {$ifc not defined __i386__ and defined CPUI386}
  40. {$setc __i386__ := 1}
  41. {$elsec}
  42. {$setc __i386__ := 0}
  43. {$endc}
  44. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  45. {$error Conflicting definitions for __ppc__ and __i386__}
  46. {$endc}
  47. {$ifc defined __ppc__ and __ppc__}
  48. {$setc TARGET_CPU_PPC := TRUE}
  49. {$setc TARGET_CPU_X86 := FALSE}
  50. {$elifc defined __i386__ and __i386__}
  51. {$setc TARGET_CPU_PPC := FALSE}
  52. {$setc TARGET_CPU_X86 := TRUE}
  53. {$elsec}
  54. {$error Neither __ppc__ nor __i386__ is defined.}
  55. {$endc}
  56. {$setc TARGET_CPU_PPC_64 := FALSE}
  57. {$ifc defined FPC_BIG_ENDIAN}
  58. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  59. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  60. {$elifc defined FPC_LITTLE_ENDIAN}
  61. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  62. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  63. {$elsec}
  64. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  65. {$endc}
  66. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  67. {$setc CALL_NOT_IN_CARBON := FALSE}
  68. {$setc OLDROUTINENAMES := FALSE}
  69. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  70. {$setc OPAQUE_UPP_TYPES := TRUE}
  71. {$setc OTCARBONAPPLICATION := TRUE}
  72. {$setc OTKERNEL := FALSE}
  73. {$setc PM_USE_SESSION_APIS := TRUE}
  74. {$setc TARGET_API_MAC_CARBON := TRUE}
  75. {$setc TARGET_API_MAC_OS8 := FALSE}
  76. {$setc TARGET_API_MAC_OSX := TRUE}
  77. {$setc TARGET_CARBON := TRUE}
  78. {$setc TARGET_CPU_68K := FALSE}
  79. {$setc TARGET_CPU_MIPS := FALSE}
  80. {$setc TARGET_CPU_SPARC := FALSE}
  81. {$setc TARGET_OS_MAC := TRUE}
  82. {$setc TARGET_OS_UNIX := FALSE}
  83. {$setc TARGET_OS_WIN32 := FALSE}
  84. {$setc TARGET_RT_MAC_68881 := FALSE}
  85. {$setc TARGET_RT_MAC_CFM := FALSE}
  86. {$setc TARGET_RT_MAC_MACHO := TRUE}
  87. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  88. {$setc TYPE_BOOL := FALSE}
  89. {$setc TYPE_EXTENDED := FALSE}
  90. {$setc TYPE_LONGLONG := TRUE}
  91. uses MacTypes;
  92. {$ALIGN MAC68K}
  93. const
  94. fixed1 = $00010000;
  95. fract1 = $40000000;
  96. positiveInfinity = $7FFFFFFF;
  97. negativeInfinity = $80000000;
  98. {
  99. FixRatio, FixMul, and FixRound were previously in ToolUtils.h
  100. }
  101. {
  102. * FixRatio()
  103. *
  104. * Availability:
  105. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  106. * CarbonLib: in CarbonLib 1.0 and later
  107. * Mac OS X: in version 10.0 and later
  108. }
  109. function FixRatio(numer: SInt16; denom: SInt16): Fixed; external name '_FixRatio';
  110. {
  111. * FixMul()
  112. *
  113. * Availability:
  114. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  115. * CarbonLib: in CarbonLib 1.0 and later
  116. * Mac OS X: in version 10.0 and later
  117. }
  118. function FixMul(a: Fixed; b: Fixed): Fixed; external name '_FixMul';
  119. {
  120. * FixRound()
  121. *
  122. * Availability:
  123. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  124. * CarbonLib: in CarbonLib 1.0 and later
  125. * Mac OS X: in version 10.0 and later
  126. }
  127. function FixRound(x: Fixed): SInt16; external name '_FixRound';
  128. {
  129. * Fix2Frac()
  130. *
  131. * Availability:
  132. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  133. * CarbonLib: in CarbonLib 1.0 and later
  134. * Mac OS X: in version 10.0 and later
  135. }
  136. function Fix2Frac(x: Fixed): Fract; external name '_Fix2Frac';
  137. {
  138. * Fix2Long()
  139. *
  140. * Availability:
  141. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  142. * CarbonLib: in CarbonLib 1.0 and later
  143. * Mac OS X: in version 10.0 and later
  144. }
  145. function Fix2Long(x: Fixed): SInt32; external name '_Fix2Long';
  146. {
  147. * Long2Fix()
  148. *
  149. * Availability:
  150. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  151. * CarbonLib: in CarbonLib 1.0 and later
  152. * Mac OS X: in version 10.0 and later
  153. }
  154. function Long2Fix(x: SInt32): Fixed; external name '_Long2Fix';
  155. {
  156. * Frac2Fix()
  157. *
  158. * Availability:
  159. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  160. * CarbonLib: in CarbonLib 1.0 and later
  161. * Mac OS X: in version 10.0 and later
  162. }
  163. function Frac2Fix(x: Fract): Fixed; external name '_Frac2Fix';
  164. {
  165. * FracMul()
  166. *
  167. * Availability:
  168. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  169. * CarbonLib: in CarbonLib 1.0 and later
  170. * Mac OS X: in version 10.0 and later
  171. }
  172. function FracMul(x: Fract; y: Fract): Fract; external name '_FracMul';
  173. {
  174. * FixDiv()
  175. *
  176. * Availability:
  177. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  178. * CarbonLib: in CarbonLib 1.0 and later
  179. * Mac OS X: in version 10.0 and later
  180. }
  181. function FixDiv(x: Fixed; y: Fixed): Fixed; external name '_FixDiv';
  182. {
  183. * FracDiv()
  184. *
  185. * Availability:
  186. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  187. * CarbonLib: in CarbonLib 1.0 and later
  188. * Mac OS X: in version 10.0 and later
  189. }
  190. function FracDiv(x: Fract; y: Fract): Fract; external name '_FracDiv';
  191. {
  192. * FracSqrt()
  193. *
  194. * Availability:
  195. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  196. * CarbonLib: in CarbonLib 1.0 and later
  197. * Mac OS X: in version 10.0 and later
  198. }
  199. function FracSqrt(x: Fract): Fract; external name '_FracSqrt';
  200. {
  201. * FracSin()
  202. *
  203. * Availability:
  204. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  205. * CarbonLib: in CarbonLib 1.0 and later
  206. * Mac OS X: in version 10.0 and later
  207. }
  208. function FracSin(x: Fixed): Fract; external name '_FracSin';
  209. {
  210. * FracCos()
  211. *
  212. * Availability:
  213. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  214. * CarbonLib: in CarbonLib 1.0 and later
  215. * Mac OS X: in version 10.0 and later
  216. }
  217. function FracCos(x: Fixed): Fract; external name '_FracCos';
  218. {
  219. * FixATan2()
  220. *
  221. * Availability:
  222. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  223. * CarbonLib: in CarbonLib 1.0 and later
  224. * Mac OS X: in version 10.0 and later
  225. }
  226. function FixATan2(x: SInt32; y: SInt32): Fixed; external name '_FixATan2';
  227. {
  228. Frac2X, Fix2X, X2Fix, and X2Frac translate to and from
  229. the floating point type "extended" (that's what the X is for).
  230. On the original Mac this was 80-bits and the functions could be
  231. accessed via A-Traps. When the 68881 co-processor was added,
  232. it used 96-bit floating point types, so the A-Traps could not
  233. be used. When PowerPC was added, it used 64-bit floating point
  234. types, so yet another prototype was added.
  235. }
  236. {$ifc TARGET_CPU_68K}
  237. {$ifc TARGET_RT_MAC_68881}
  238. {$ifc CALL_NOT_IN_CARBON}
  239. {
  240. * Frac2X()
  241. *
  242. * Availability:
  243. * Non-Carbon CFM: not available
  244. * CarbonLib: not available
  245. * Mac OS X: not available
  246. }
  247. function Frac2X(x: Fract): extended; external name '_Frac2X';
  248. {
  249. * Fix2X()
  250. *
  251. * Availability:
  252. * Non-Carbon CFM: not available
  253. * CarbonLib: not available
  254. * Mac OS X: not available
  255. }
  256. function Fix2X(x: Fixed): extended; external name '_Fix2X';
  257. {
  258. * X2Fix()
  259. *
  260. * Availability:
  261. * Non-Carbon CFM: not available
  262. * CarbonLib: not available
  263. * Mac OS X: not available
  264. }
  265. function X2Fix(x: extended): Fixed; external name '_X2Fix';
  266. {
  267. * X2Frac()
  268. *
  269. * Availability:
  270. * Non-Carbon CFM: not available
  271. * CarbonLib: not available
  272. * Mac OS X: not available
  273. }
  274. function X2Frac(x: extended): Fract; external name '_X2Frac';
  275. {$endc} {CALL_NOT_IN_CARBON}
  276. {$elsec}
  277. {$ifc CALL_NOT_IN_CARBON}
  278. {
  279. * Frac2X()
  280. *
  281. * Availability:
  282. * Non-Carbon CFM: not available
  283. * CarbonLib: not available
  284. * Mac OS X: not available
  285. }
  286. function Frac2X(x: Fract): extended; external name '_Frac2X';
  287. {
  288. * Fix2X()
  289. *
  290. * Availability:
  291. * Non-Carbon CFM: not available
  292. * CarbonLib: not available
  293. * Mac OS X: not available
  294. }
  295. function Fix2X(x: Fixed): extended; external name '_Fix2X';
  296. {
  297. * X2Fix()
  298. *
  299. * Availability:
  300. * Non-Carbon CFM: not available
  301. * CarbonLib: not available
  302. * Mac OS X: not available
  303. }
  304. function X2Fix(x: extended): Fixed; external name '_X2Fix';
  305. {
  306. * X2Frac()
  307. *
  308. * Availability:
  309. * Non-Carbon CFM: not available
  310. * CarbonLib: not available
  311. * Mac OS X: not available
  312. }
  313. function X2Frac(x: extended): Fract; external name '_X2Frac';
  314. {$endc} {CALL_NOT_IN_CARBON}
  315. {$endc} {TARGET_RT_MAC_68881}
  316. {$elsec}
  317. {
  318. * Frac2X()
  319. *
  320. * Availability:
  321. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  322. * CarbonLib: in CarbonLib 1.0 and later
  323. * Mac OS X: in version 10.0 and later
  324. }
  325. function Frac2X(x: Fract): Double; external name '_Frac2X';
  326. {
  327. * Fix2X()
  328. *
  329. * Availability:
  330. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  331. * CarbonLib: in CarbonLib 1.0 and later
  332. * Mac OS X: in version 10.0 and later
  333. }
  334. function Fix2X(x: Fixed): Double; external name '_Fix2X';
  335. {
  336. * X2Fix()
  337. *
  338. * Availability:
  339. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  340. * CarbonLib: in CarbonLib 1.0 and later
  341. * Mac OS X: in version 10.0 and later
  342. }
  343. function X2Fix(x: Double): Fixed; external name '_X2Fix';
  344. {
  345. * X2Frac()
  346. *
  347. * Availability:
  348. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  349. * CarbonLib: in CarbonLib 1.0 and later
  350. * Mac OS X: in version 10.0 and later
  351. }
  352. function X2Frac(x: Double): Fract; external name '_X2Frac';
  353. {$endc} {TARGET_CPU_68K}
  354. { QuickTime 3.0 makes these Wide routines available on other platforms }
  355. {$ifc TARGET_CPU_PPC OR NOT TARGET_OS_MAC}
  356. {
  357. * WideCompare()
  358. *
  359. * Availability:
  360. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  361. * CarbonLib: in CarbonLib 1.0 and later
  362. * Mac OS X: in version 10.0 and later
  363. }
  364. function WideCompare(const (*var*) target: wide; const (*var*) source: wide): SInt16; external name '_WideCompare';
  365. {
  366. * WideAdd()
  367. *
  368. * Availability:
  369. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  370. * CarbonLib: in CarbonLib 1.0 and later
  371. * Mac OS X: in version 10.0 and later
  372. }
  373. function WideAdd(var target: wide; const (*var*) source: wide): widePtr; external name '_WideAdd';
  374. {
  375. * WideSubtract()
  376. *
  377. * Availability:
  378. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  379. * CarbonLib: in CarbonLib 1.0 and later
  380. * Mac OS X: in version 10.0 and later
  381. }
  382. function WideSubtract(var target: wide; const (*var*) source: wide): widePtr; external name '_WideSubtract';
  383. {
  384. * WideNegate()
  385. *
  386. * Availability:
  387. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  388. * CarbonLib: in CarbonLib 1.0 and later
  389. * Mac OS X: in version 10.0 and later
  390. }
  391. function WideNegate(var target: wide): widePtr; external name '_WideNegate';
  392. {
  393. * WideShift()
  394. *
  395. * Availability:
  396. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  397. * CarbonLib: in CarbonLib 1.0 and later
  398. * Mac OS X: in version 10.0 and later
  399. }
  400. function WideShift(var target: wide; shift: SInt32): widePtr; external name '_WideShift';
  401. {
  402. * WideSquareRoot()
  403. *
  404. * Availability:
  405. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  406. * CarbonLib: in CarbonLib 1.0 and later
  407. * Mac OS X: in version 10.0 and later
  408. }
  409. function WideSquareRoot(const (*var*) source: wide): UInt32; external name '_WideSquareRoot';
  410. {
  411. * WideMultiply()
  412. *
  413. * Availability:
  414. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  415. * CarbonLib: in CarbonLib 1.0 and later
  416. * Mac OS X: in version 10.0 and later
  417. }
  418. function WideMultiply(multiplicand: SInt32; multiplier: SInt32; var target: wide): widePtr; external name '_WideMultiply';
  419. { returns the quotient }
  420. {
  421. * WideDivide()
  422. *
  423. * Availability:
  424. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  425. * CarbonLib: in CarbonLib 1.0 and later
  426. * Mac OS X: in version 10.0 and later
  427. }
  428. function WideDivide(const (*var*) dividend: wide; divisor: SInt32; var remainder: SInt32): SInt32; external name '_WideDivide';
  429. { quotient replaces dividend }
  430. {
  431. * WideWideDivide()
  432. *
  433. * Availability:
  434. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  435. * CarbonLib: in CarbonLib 1.0 and later
  436. * Mac OS X: in version 10.0 and later
  437. }
  438. function WideWideDivide(var dividend: wide; divisor: SInt32; var remainder: SInt32): widePtr; external name '_WideWideDivide';
  439. {
  440. * WideBitShift()
  441. *
  442. * Availability:
  443. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  444. * CarbonLib: in CarbonLib 1.0 and later
  445. * Mac OS X: in version 10.0 and later
  446. }
  447. function WideBitShift(var src: wide; shift: SInt32): widePtr; external name '_WideBitShift';
  448. {$endc}
  449. {$ALIGN MAC68K}
  450. end.