home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / ODMATH.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  5KB  |  173 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: odutils
  5. //
  6. //   CLASSES: none
  7. //
  8. //   ORIGINS: 82,27
  9. //
  10. //
  11. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12. //   All Rights Reserved
  13. //   Licensed Materials - Property of IBM
  14. //   US Government Users Restricted Rights - Use, duplication or
  15. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16. //       
  17. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23. //   OR PERFORMANCE OF THIS SOFTWARE.
  24. //
  25. //====END_GENERATED_PROLOG========================================
  26. //
  27. // @(#) 1.9 com/src/utils/include/ODMath.h, odutils, od96os2, odos29646d 10/10/96 11:26:29 [ 11/15/96 15:29:00 ]
  28. /*
  29.     File:        ODMath.h
  30.  
  31.     Contains:    Math routines (fixed-point and wide) for OpenDoc.
  32.  
  33.     Owned by:    Jens Alfke
  34.  
  35.     Copyright:    ⌐ 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  36.  
  37.     
  38.     In Progress:
  39.         
  40. */
  41.  
  42.  
  43. #ifndef _ODMATH_
  44. #define _ODMATH_
  45.  
  46.  
  47. #ifndef _ODTYPES_
  48. #include "ODTypes.h"
  49. #endif
  50.  
  51. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  52. #ifndef _ODTYPESP_
  53. #include <ODTypesP.h>
  54. #endif
  55. #endif // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  56.  
  57. #if _PLATFORM_MACINTOSH_
  58.     #ifndef __FIXMATH__
  59.     #include <FixMath.h>
  60.     #endif
  61.     #ifndef __TOOLUTILS__
  62.     #include <ToolUtils.h>
  63.     #endif
  64. #endif
  65.  
  66.  
  67. #if _PLATFORM_MACINTOSH_
  68. typedef wide ODWide;
  69. #elif defined(_PLATFORM_UNIX_)
  70. typedef long long ODWide;
  71. #else
  72. struct ODWide {                        // 64-bit integer
  73.     ODSLong hi;                            // High order longword comes first
  74.     ODULong lo;                            // Then low-order (which has no sign bit!)
  75. };
  76. #endif
  77.  
  78.  
  79. const ODFixed kODFixed1                = 0x00010000;
  80. const ODFixed kODFixedHalf            = 0x00008000;
  81. const ODFract kODFract1                = 0x40000000;
  82. const ODFixed kODFixedInfinity        = 0x7FFFFFFF;    // Fract as well
  83. const ODFixed kODFixedMinusInfinity    = 0x80000000;
  84.  
  85.  
  86. // Some of these fns are coded in assembly on 68k, so make calling conventions C:
  87. extern "C" {
  88.  
  89.  
  90. #define ODFixedRound(a)        ((ODSShort)((ODFixed)(a) + kODFixedHalf >> 16))
  91. #define ODIntToFixed(a)        ((ODFixed)(a) << 16)
  92. #define ODFixedToFract(a)    ((ODFract)(a) << 14)
  93. #define ODFractToFixed(a)    ((ODFixed)(a) + 8192L >> 14)
  94. #if defined(OD_BUG)
  95. #define ODFixedToFloat(a)    ((double)((ODFixed)(a)) / kODFixed1)
  96. #else // OD_BUG
  97. #define ODFixedToFloat(a)    ((ODFixed)(a) / 65536.0)
  98. #endif // OD_BUG
  99. #define ODFloatToFixed(a)    ((ODFixed)((double_t)(a) * 65536.0))
  100. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  101. #define ODFractToFloat(a)    ((double)((ODFract)(a)) / kODFract1)
  102. #endif // defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_) || defined(_PLATFORM_UNIX_)
  103.  
  104.  
  105. // These fixed-point math routines return infinity (see above) on overflow.
  106.  
  107. #if _PLATFORM_MACINTOSH_
  108.     #define ODFixedMultiply        FixMul
  109.     #define ODFixedDivide        FixDiv
  110.     #define ODFractMultiply        FracMul
  111.     #define ODFractDivide        FracDiv
  112.     
  113.     #ifdef __cplusplus
  114.     inline ODWide* ODWideMultiply( ODSLong a, ODSLong b, ODWide *result )
  115.     {
  116.         LongMul(a,b,(Int64Bit*)result);
  117.         return result;
  118.     }
  119.     #endif
  120. #else
  121. ODFixed    ODFixedMultiply( ODFixed a, ODFixed b );
  122. ODFixed    ODFixedDivide( ODFixed a, ODFixed b );
  123. ODFract    ODFractMultiply( ODFract a, ODFract b );
  124. ODFract    ODFractDivide( ODFract a, ODFract b );
  125. ODWide*    ODWideMultiply( ODSLong a, ODSLong b, ODWide *result );
  126. #endif
  127.  
  128. /*
  129. #if defined(_PLATFORM_MACINTOSH_) && (defined(powerc) || defined(__powerc))
  130.     #define ODWideCompare        WideCompare
  131.     #define ODWideNegate        WideNegate
  132.     #define ODWideShift            WideShift
  133.     #define ODWideAdd            WideAdd
  134.     #define ODWideSubtract        WideSubtract
  135.     #define ODWideMultiply        WideMultiply
  136.     #define ODWideDivide        WideDivide
  137.     #define ODWideSquareRoot    WideSquareRoot
  138. #else
  139. */
  140. ODSShort ODWideCompare( const ODWide*, const ODWide* );
  141. ODWide*    ODWideNegate( ODWide* );
  142. ODWide*    ODWideShift( ODWide*, ODSShort bits );    // Positive is toward MSB
  143. ODWide*    ODWideAdd( ODWide*, const ODWide* );
  144. ODWide*    ODWideSubtract( ODWide*, const ODWide* );
  145.  
  146. ODSLong    ODWideDivide( const ODWide *dividend,
  147.                             ODSLong divisor, ODSLong *remainder);
  148. ODULong ODWideSquareRoot( const ODWide *src );
  149. /*
  150. #endif
  151. */
  152. #define kODIgnoreRemainder  ((ODSLong*)-1L)    // Use as remainder in ODWideDivide
  153.  
  154. #if !defined(_PLATFORM_UNIX_)
  155. #define ODWideIsLong(w) ((w)->hi ==  0 && (long)(w)->lo >= 0 || \
  156.                           (w)->hi == -1 && (long)(w)->lo < 0)
  157. #else // defined(_PLATFORM_UNIX_)
  158. const ODWide kODMaxLong = 2147483647ll;
  159. #define ODWideIsLong(w) (-2147483647ll <= *w && *w <= 2147483647ll)
  160. #endif // !defined(_PLATFORM_UNIX_)
  161.  
  162. ODFract    ODFractSinCos( ODFixed radians, ODFract *cos );    // returns sin
  163.  
  164. ODSShort    ODFirstBit( ODSLong );            // Returns index (0-32) of 1st bit
  165. #if defined(_PLATFORM_UNIX_)
  166. ODSShort    ODWideFirstBit( ODWide );            // Returns index (0-64) of 1st bit
  167. #endif // defined(_PLATFORM_UNIX_)
  168.  
  169.  
  170. }    // End of extern "C" {
  171.  
  172. #endif /*_ODMATH_*/
  173.