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.

551 lines
12 KiB

  1. /*
  2. File: FixMath.h
  3. Contains: Fixed Math Interfaces.
  4. Version: QuickTime 7.3
  5. Copyright: (c) 2007 (c) 1985-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 __FIXMATH__
  11. #define __FIXMATH__
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.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. #define fixed1 ((Fixed) 0x00010000L)
  25. #define fract1 ((Fract) 0x40000000L)
  26. #define positiveInfinity ((long) 0x7FFFFFFFL)
  27. #define negativeInfinity ((long) 0x80000000L)
  28. /*
  29. FixRatio, FixMul, and FixRound were previously in ToolUtils.h
  30. */
  31. /*
  32. * FixRatio()
  33. *
  34. * Availability:
  35. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  36. * CarbonLib: in CarbonLib 1.0 and later
  37. * Mac OS X: in version 10.0 and later
  38. */
  39. EXTERN_API( Fixed )
  40. FixRatio(
  41. short numer,
  42. short denom) ONEWORDINLINE(0xA869);
  43. /*
  44. * FixMul()
  45. *
  46. * Availability:
  47. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  48. * CarbonLib: in CarbonLib 1.0 and later
  49. * Mac OS X: in version 10.0 and later
  50. */
  51. EXTERN_API( Fixed )
  52. FixMul(
  53. Fixed a,
  54. Fixed b) ONEWORDINLINE(0xA868);
  55. /*
  56. * FixRound()
  57. *
  58. * Availability:
  59. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  60. * CarbonLib: in CarbonLib 1.0 and later
  61. * Mac OS X: in version 10.0 and later
  62. */
  63. EXTERN_API( short )
  64. FixRound(Fixed x) ONEWORDINLINE(0xA86C);
  65. /*
  66. * Fix2Frac()
  67. *
  68. * Availability:
  69. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  70. * CarbonLib: in CarbonLib 1.0 and later
  71. * Mac OS X: in version 10.0 and later
  72. */
  73. EXTERN_API( Fract )
  74. Fix2Frac(Fixed x) ONEWORDINLINE(0xA841);
  75. /*
  76. * Fix2Long()
  77. *
  78. * Availability:
  79. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  80. * CarbonLib: in CarbonLib 1.0 and later
  81. * Mac OS X: in version 10.0 and later
  82. */
  83. EXTERN_API( long )
  84. Fix2Long(Fixed x) ONEWORDINLINE(0xA840);
  85. /*
  86. * Long2Fix()
  87. *
  88. * Availability:
  89. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  90. * CarbonLib: in CarbonLib 1.0 and later
  91. * Mac OS X: in version 10.0 and later
  92. */
  93. EXTERN_API( Fixed )
  94. Long2Fix(long x) ONEWORDINLINE(0xA83F);
  95. /*
  96. * Frac2Fix()
  97. *
  98. * Availability:
  99. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  100. * CarbonLib: in CarbonLib 1.0 and later
  101. * Mac OS X: in version 10.0 and later
  102. */
  103. EXTERN_API( Fixed )
  104. Frac2Fix(Fract x) ONEWORDINLINE(0xA842);
  105. /*
  106. * FracMul()
  107. *
  108. * Availability:
  109. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  110. * CarbonLib: in CarbonLib 1.0 and later
  111. * Mac OS X: in version 10.0 and later
  112. */
  113. EXTERN_API( Fract )
  114. FracMul(
  115. Fract x,
  116. Fract y) ONEWORDINLINE(0xA84A);
  117. /*
  118. * FixDiv()
  119. *
  120. * Availability:
  121. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  122. * CarbonLib: in CarbonLib 1.0 and later
  123. * Mac OS X: in version 10.0 and later
  124. */
  125. EXTERN_API( Fixed )
  126. FixDiv(
  127. Fixed x,
  128. Fixed y) ONEWORDINLINE(0xA84D);
  129. /*
  130. * FracDiv()
  131. *
  132. * Availability:
  133. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  134. * CarbonLib: in CarbonLib 1.0 and later
  135. * Mac OS X: in version 10.0 and later
  136. */
  137. EXTERN_API( Fract )
  138. FracDiv(
  139. Fract x,
  140. Fract y) ONEWORDINLINE(0xA84B);
  141. /*
  142. * FracSqrt()
  143. *
  144. * Availability:
  145. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  146. * CarbonLib: in CarbonLib 1.0 and later
  147. * Mac OS X: in version 10.0 and later
  148. */
  149. EXTERN_API( Fract )
  150. FracSqrt(Fract x) ONEWORDINLINE(0xA849);
  151. /*
  152. * FracSin()
  153. *
  154. * Availability:
  155. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  156. * CarbonLib: in CarbonLib 1.0 and later
  157. * Mac OS X: in version 10.0 and later
  158. */
  159. EXTERN_API( Fract )
  160. FracSin(Fixed x) ONEWORDINLINE(0xA848);
  161. /*
  162. * FracCos()
  163. *
  164. * Availability:
  165. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  166. * CarbonLib: in CarbonLib 1.0 and later
  167. * Mac OS X: in version 10.0 and later
  168. */
  169. EXTERN_API( Fract )
  170. FracCos(Fixed x) ONEWORDINLINE(0xA847);
  171. /*
  172. * FixATan2()
  173. *
  174. * Availability:
  175. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  176. * CarbonLib: in CarbonLib 1.0 and later
  177. * Mac OS X: in version 10.0 and later
  178. */
  179. EXTERN_API( Fixed )
  180. FixATan2(
  181. long x,
  182. long y) ONEWORDINLINE(0xA818);
  183. /*
  184. Frac2X, Fix2X, X2Fix, and X2Frac translate to and from
  185. the floating point type "extended" (that's what the X is for).
  186. On the original Mac this was 80-bits and the functions could be
  187. accessed via A-Traps. When the 68881 co-processor was added,
  188. it used 96-bit floating point types, so the A-Traps could not
  189. be used. When PowerPC was added, it used 64-bit floating point
  190. types, so yet another prototype was added.
  191. */
  192. #if TARGET_CPU_68K
  193. #if TARGET_RT_MAC_68881
  194. #if CALL_NOT_IN_CARBON
  195. /*
  196. * Frac2X()
  197. *
  198. * Availability:
  199. * Non-Carbon CFM: not available
  200. * CarbonLib: not available
  201. * Mac OS X: not available
  202. */
  203. EXTERN_API( long double )
  204. Frac2X(Fract x);
  205. /*
  206. * Fix2X()
  207. *
  208. * Availability:
  209. * Non-Carbon CFM: not available
  210. * CarbonLib: not available
  211. * Mac OS X: not available
  212. */
  213. EXTERN_API( long double )
  214. Fix2X(Fixed x);
  215. /*
  216. * X2Fix()
  217. *
  218. * Availability:
  219. * Non-Carbon CFM: not available
  220. * CarbonLib: not available
  221. * Mac OS X: not available
  222. */
  223. EXTERN_API( Fixed )
  224. X2Fix(long double x);
  225. /*
  226. * X2Frac()
  227. *
  228. * Availability:
  229. * Non-Carbon CFM: not available
  230. * CarbonLib: not available
  231. * Mac OS X: not available
  232. */
  233. EXTERN_API( Fract )
  234. X2Frac(long double x);
  235. #endif /* CALL_NOT_IN_CARBON */
  236. #else
  237. #if CALL_NOT_IN_CARBON
  238. /*
  239. * Frac2X()
  240. *
  241. * Availability:
  242. * Non-Carbon CFM: not available
  243. * CarbonLib: not available
  244. * Mac OS X: not available
  245. */
  246. EXTERN_API( long double )
  247. Frac2X(Fract x) ONEWORDINLINE(0xA845);
  248. /*
  249. * Fix2X()
  250. *
  251. * Availability:
  252. * Non-Carbon CFM: not available
  253. * CarbonLib: not available
  254. * Mac OS X: not available
  255. */
  256. EXTERN_API( long double )
  257. Fix2X(Fixed x) ONEWORDINLINE(0xA843);
  258. /*
  259. * X2Fix()
  260. *
  261. * Availability:
  262. * Non-Carbon CFM: not available
  263. * CarbonLib: not available
  264. * Mac OS X: not available
  265. */
  266. EXTERN_API( Fixed )
  267. X2Fix(long double x) ONEWORDINLINE(0xA844);
  268. /*
  269. * X2Frac()
  270. *
  271. * Availability:
  272. * Non-Carbon CFM: not available
  273. * CarbonLib: not available
  274. * Mac OS X: not available
  275. */
  276. EXTERN_API( Fract )
  277. X2Frac(long double x) ONEWORDINLINE(0xA846);
  278. #endif /* CALL_NOT_IN_CARBON */
  279. #endif /* TARGET_RT_MAC_68881 */
  280. #else
  281. /*
  282. * Frac2X()
  283. *
  284. * Availability:
  285. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  286. * CarbonLib: in CarbonLib 1.0 and later
  287. * Mac OS X: in version 10.0 and later
  288. */
  289. EXTERN_API( double )
  290. Frac2X(Fract x);
  291. /*
  292. * Fix2X()
  293. *
  294. * Availability:
  295. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  296. * CarbonLib: in CarbonLib 1.0 and later
  297. * Mac OS X: in version 10.0 and later
  298. */
  299. EXTERN_API( double )
  300. Fix2X(Fixed x);
  301. /*
  302. * X2Fix()
  303. *
  304. * Availability:
  305. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  306. * CarbonLib: in CarbonLib 1.0 and later
  307. * Mac OS X: in version 10.0 and later
  308. */
  309. EXTERN_API( Fixed )
  310. X2Fix(double x);
  311. /*
  312. * X2Frac()
  313. *
  314. * Availability:
  315. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  316. * CarbonLib: in CarbonLib 1.0 and later
  317. * Mac OS X: in version 10.0 and later
  318. */
  319. EXTERN_API( Fract )
  320. X2Frac(double x);
  321. #endif /* TARGET_CPU_68K */
  322. /* QuickTime 3.0 makes these Wide routines available on other platforms*/
  323. #if TARGET_CPU_PPC || !TARGET_OS_MAC || TARGET_CPU_X86
  324. /*
  325. * WideCompare()
  326. *
  327. * Availability:
  328. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  329. * CarbonLib: in CarbonLib 1.0 and later
  330. * Mac OS X: in version 10.0 and later
  331. */
  332. EXTERN_API_C( short )
  333. WideCompare(
  334. const wide * target,
  335. const wide * source);
  336. /*
  337. * WideAdd()
  338. *
  339. * Availability:
  340. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  341. * CarbonLib: in CarbonLib 1.0 and later
  342. * Mac OS X: in version 10.0 and later
  343. */
  344. EXTERN_API_C( wide * )
  345. WideAdd(
  346. wide * target,
  347. const wide * source);
  348. /*
  349. * WideSubtract()
  350. *
  351. * Availability:
  352. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  353. * CarbonLib: in CarbonLib 1.0 and later
  354. * Mac OS X: in version 10.0 and later
  355. */
  356. EXTERN_API_C( wide * )
  357. WideSubtract(
  358. wide * target,
  359. const wide * source);
  360. /*
  361. * WideNegate()
  362. *
  363. * Availability:
  364. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  365. * CarbonLib: in CarbonLib 1.0 and later
  366. * Mac OS X: in version 10.0 and later
  367. */
  368. EXTERN_API_C( wide * )
  369. WideNegate(wide * target);
  370. /*
  371. * WideShift()
  372. *
  373. * Availability:
  374. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  375. * CarbonLib: in CarbonLib 1.0 and later
  376. * Mac OS X: in version 10.0 and later
  377. */
  378. EXTERN_API_C( wide * )
  379. WideShift(
  380. wide * target,
  381. long shift);
  382. /*
  383. * WideSquareRoot()
  384. *
  385. * Availability:
  386. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  387. * CarbonLib: in CarbonLib 1.0 and later
  388. * Mac OS X: in version 10.0 and later
  389. */
  390. EXTERN_API_C( unsigned long )
  391. WideSquareRoot(const wide * source);
  392. /*
  393. * WideMultiply()
  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. EXTERN_API_C( wide * )
  401. WideMultiply(
  402. long multiplicand,
  403. long multiplier,
  404. wide * target);
  405. /* returns the quotient */
  406. /*
  407. * WideDivide()
  408. *
  409. * Availability:
  410. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  411. * CarbonLib: in CarbonLib 1.0 and later
  412. * Mac OS X: in version 10.0 and later
  413. */
  414. EXTERN_API_C( long )
  415. WideDivide(
  416. const wide * dividend,
  417. long divisor,
  418. long * remainder);
  419. /* quotient replaces dividend */
  420. /*
  421. * WideWideDivide()
  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. EXTERN_API_C( wide * )
  429. WideWideDivide(
  430. wide * dividend,
  431. long divisor,
  432. long * remainder);
  433. /*
  434. * WideBitShift()
  435. *
  436. * Availability:
  437. * Non-Carbon CFM: in InterfaceLib 7.1 and later
  438. * CarbonLib: in CarbonLib 1.0 and later
  439. * Mac OS X: in version 10.0 and later
  440. */
  441. EXTERN_API_C( wide * )
  442. WideBitShift(
  443. wide * src,
  444. long shift);
  445. #endif /* TARGET_CPU_PPC || !TARGET_OS_MAC || TARGET_CPU_X86 */
  446. #ifdef PRAGMA_IMPORT_OFF
  447. #pragma import off
  448. #elif PRAGMA_IMPORT
  449. #pragma import reset
  450. #endif
  451. #ifdef __cplusplus
  452. }
  453. #endif
  454. #endif /* __FIXMATH__ */