home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Interfaces&Libraries / Universal / Interfaces / CIncludes / FixMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-17  |  4.9 KB  |  226 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        FixMath.h
  3.  
  4.      Contains:    Fixed Math Interfaces.
  5.  
  6.      Version:    Technology:    Mac OS 8
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1985-1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __FIXMATH__
  18. #define __FIXMATH__
  19.  
  20. #ifndef __MACTYPES__
  21. #include <MacTypes.h>
  22. #endif
  23.  
  24.  
  25.  
  26. #if PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29.  
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33.  
  34. #if PRAGMA_IMPORT
  35. #pragma import on
  36. #endif
  37.  
  38. #if PRAGMA_STRUCT_ALIGN
  39.     #pragma options align=mac68k
  40. #elif PRAGMA_STRUCT_PACKPUSH
  41.     #pragma pack(push, 2)
  42. #elif PRAGMA_STRUCT_PACK
  43.     #pragma pack(2)
  44. #endif
  45.  
  46.  
  47.  
  48. #define fixed1                ((Fixed) 0x00010000L)
  49. #define fract1                ((Fract) 0x40000000L)
  50. #define positiveInfinity    ((long)  0x7FFFFFFFL)
  51. #define negativeInfinity    ((long)  0x80000000L)
  52. /*
  53.     FixRatio, FixMul, and FixRound were previously in ToolUtils.h
  54. */
  55. EXTERN_API( Fixed )
  56. FixRatio                        (short                     numer,
  57.                                  short                     denom)                                ONEWORDINLINE(0xA869);
  58.  
  59. EXTERN_API( Fixed )
  60. FixMul                            (Fixed                     a,
  61.                                  Fixed                     b)                                    ONEWORDINLINE(0xA868);
  62.  
  63. EXTERN_API( short )
  64. FixRound                        (Fixed                     x)                                    ONEWORDINLINE(0xA86C);
  65.  
  66.  
  67. EXTERN_API( Fract )
  68. Fix2Frac                        (Fixed                     x)                                    ONEWORDINLINE(0xA841);
  69.  
  70. EXTERN_API( long )
  71. Fix2Long                        (Fixed                     x)                                    ONEWORDINLINE(0xA840);
  72.  
  73. EXTERN_API( Fixed )
  74. Long2Fix                        (long                     x)                                    ONEWORDINLINE(0xA83F);
  75.  
  76. EXTERN_API( Fixed )
  77. Frac2Fix                        (Fract                     x)                                    ONEWORDINLINE(0xA842);
  78.  
  79. EXTERN_API( Fract )
  80. FracMul                            (Fract                     x,
  81.                                  Fract                     y)                                    ONEWORDINLINE(0xA84A);
  82.  
  83. EXTERN_API( Fixed )
  84. FixDiv                            (Fixed                     x,
  85.                                  Fixed                     y)                                    ONEWORDINLINE(0xA84D);
  86.  
  87. EXTERN_API( Fract )
  88. FracDiv                            (Fract                     x,
  89.                                  Fract                     y)                                    ONEWORDINLINE(0xA84B);
  90.  
  91. EXTERN_API( Fract )
  92. FracSqrt                        (Fract                     x)                                    ONEWORDINLINE(0xA849);
  93.  
  94. EXTERN_API( Fract )
  95. FracSin                            (Fixed                     x)                                    ONEWORDINLINE(0xA848);
  96.  
  97. EXTERN_API( Fract )
  98. FracCos                            (Fixed                     x)                                    ONEWORDINLINE(0xA847);
  99.  
  100. EXTERN_API( Fixed )
  101. FixATan2                        (long                     x,
  102.                                  long                     y)                                    ONEWORDINLINE(0xA818);
  103.  
  104. /*
  105.     Frac2X, Fix2X, X2Fix, and X2Frac translate to and from
  106.     the floating point type "extended" (that's what the X is for).
  107.     On the original Mac this was 80-bits and the functions could be
  108.     accessed via A-Traps.  When the 68881 co-processor was added,
  109.     it used 96-bit floating point types, so the A-Traps could not 
  110.     be used.  When PowerPC was added, it used 64-bit floating point
  111.     types, so yet another prototype was added.
  112. */
  113. #if TARGET_CPU_68K
  114. #if TARGET_RT_MAC_68881
  115. EXTERN_API( long double )
  116. Frac2X                            (Fract                     x);
  117.  
  118. EXTERN_API( long double )
  119. Fix2X                            (Fixed                     x);
  120.  
  121. EXTERN_API( Fixed )
  122. X2Fix                            (long double             x);
  123.  
  124. EXTERN_API( Fract )
  125. X2Frac                            (long double             x);
  126.  
  127. #else
  128. EXTERN_API( long double )
  129. Frac2X                            (Fract                     x)                                    ONEWORDINLINE(0xA845);
  130.  
  131. EXTERN_API( long double )
  132. Fix2X                            (Fixed                     x)                                    ONEWORDINLINE(0xA843);
  133.  
  134. EXTERN_API( Fixed )
  135. X2Fix                            (long double             x)                                    ONEWORDINLINE(0xA844);
  136.  
  137. EXTERN_API( Fract )
  138. X2Frac                            (long double             x)                                    ONEWORDINLINE(0xA846);
  139.  
  140. #endif  /* TARGET_RT_MAC_68881 */
  141.  
  142. #else
  143. EXTERN_API( double )
  144. Frac2X                            (Fract                     x);
  145.  
  146. EXTERN_API( double )
  147. Fix2X                            (Fixed                     x);
  148.  
  149. EXTERN_API( Fixed )
  150. X2Fix                            (double                 x);
  151.  
  152. EXTERN_API( Fract )
  153. X2Frac                            (double                 x);
  154.  
  155. #endif  /* TARGET_CPU_68K */
  156.  
  157. /* QuickTime 3.0 makes these Wide routines available on other platforms*/
  158. #if TARGET_CPU_PPC || !TARGET_OS_MAC
  159. EXTERN_API_C( short )
  160. WideCompare                        (const wide *            target,
  161.                                  const wide *            source);
  162.  
  163. EXTERN_API_C( WidePtr )
  164. WideAdd                            (wide *                    target,
  165.                                  const wide *            source);
  166.  
  167. EXTERN_API_C( WidePtr )
  168. WideSubtract                    (wide *                    target,
  169.                                  const wide *            source);
  170.  
  171. EXTERN_API_C( WidePtr )
  172. WideNegate                        (wide *                    target);
  173.  
  174. EXTERN_API_C( WidePtr )
  175. WideShift                        (wide *                    target,
  176.                                  long                     shift);
  177.  
  178. EXTERN_API_C( unsigned long )
  179. WideSquareRoot                    (const wide *            source);
  180.  
  181. EXTERN_API_C( WidePtr )
  182. WideMultiply                    (long                     multiplicand,
  183.                                  long                     multiplier,
  184.                                  wide *                    target);
  185.  
  186. /* returns the quotient */
  187. EXTERN_API_C( long )
  188. WideDivide                        (const wide *            dividend,
  189.                                  long                     divisor,
  190.                                  long *                    remainder);
  191.  
  192. /* quotient replaces dividend */
  193. EXTERN_API_C( WidePtr )
  194. WideWideDivide                    (wide *                    dividend,
  195.                                  long                     divisor,
  196.                                  long *                    remainder);
  197.  
  198. EXTERN_API_C( WidePtr )
  199. WideBitShift                    (wide *                    src,
  200.                                  long                     shift);
  201.  
  202. #endif  /* TARGET_CPU_PPC || !TARGET_OS_MAC */
  203.  
  204.  
  205.  
  206. #if PRAGMA_STRUCT_ALIGN
  207.     #pragma options align=reset
  208. #elif PRAGMA_STRUCT_PACKPUSH
  209.     #pragma pack(pop)
  210. #elif PRAGMA_STRUCT_PACK
  211.     #pragma pack()
  212. #endif
  213.  
  214. #ifdef PRAGMA_IMPORT_OFF
  215. #pragma import off
  216. #elif PRAGMA_IMPORT
  217. #pragma import reset
  218. #endif
  219.  
  220. #ifdef __cplusplus
  221. }
  222. #endif
  223.  
  224. #endif /* __FIXMATH__ */
  225.  
  226.