home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ODMath.h
-
- Contains: Math routines (fixed-point and wide) for OpenDoc.
-
- Owned by: Jens Alfke
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
-
- In Progress:
-
- */
-
-
- #ifndef _ODMATH_
- #define _ODMATH_
-
-
- #ifndef _ODTYPES_
- #include "ODTypes.h"
- #endif
-
- #if _PLATFORM_MACINTOSH_
- #ifndef __FIXMATH__
- #include <FixMath.h>
- #endif
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
- #endif
-
-
- #if _PLATFORM_MACINTOSH_
- typedef wide ODWide;
- #else
- struct ODWide { // 64-bit integer
- ODSLong hi; // High order longword comes first
- ODULong lo; // Then low-order (which has no sign bit!)
- };
- #endif
-
-
- const ODFixed kODFixed1 = 0x00010000;
- const ODFixed kODFixedHalf = 0x00008000;
- const ODFract kODFract1 = 0x40000000;
- const ODFixed kODFixedInfinity = 0x7FFFFFFF; // Fract as well
- const ODFixed kODFixedMinusInfinity = 0x80000000;
-
-
- // Some of these fns are coded in assembly on 68k, so make calling conventions C:
- extern "C" {
-
-
- #define ODFixedRound(a) ((ODSShort)((ODFixed)(a) + kODFixedHalf >> 16))
- #define ODIntToFixed(a) ((ODFixed)(a) << 16)
- #define ODFixedToFract(a) ((ODFract)(a) << 14)
- #define ODFractToFixed(a) ((ODFixed)(a) + 8192L >> 14)
- #define ODFixedToFloat(a) ((ODFixed)(a) / 65536.0)
- #define ODFloatToFixed(a) ((ODFixed)((double_t)(a) * 65536.0))
-
-
- // These fixed-point math routines return infinity (see above) on overflow.
-
- #if _PLATFORM_MACINTOSH_
- #define ODFixedMultiply FixMul
- #define ODFixedDivide FixDiv
- #define ODFractMultiply FracMul
- #define ODFractDivide FracDiv
-
- #ifdef __cplusplus
- inline ODWide* ODWideMultiply( ODSLong a, ODSLong b, ODWide *result )
- {
- LongMul(a,b,(Int64Bit*)result);
- return result;
- }
- #endif
- #else
- ODFixed ODFixedMultiply( ODFixed a, ODFixed b );
- ODFixed ODFixedDivide( ODFixed a, ODFixed b );
- ODFract ODFractMultiply( ODFract a, ODFract b );
- ODFract ODFractDivide( ODFract a, ODFract b );
- ODWide* ODWideMultiply( ODSLong a, ODSLong b, ODWide *result );
- #endif
-
- /*
- #if defined(_PLATFORM_MACINTOSH_) && (defined(powerc) || defined(__powerc))
- #define ODWideCompare WideCompare
- #define ODWideNegate WideNegate
- #define ODWideShift WideShift
- #define ODWideAdd WideAdd
- #define ODWideSubtract WideSubtract
- #define ODWideMultiply WideMultiply
- #define ODWideDivide WideDivide
- #define ODWideSquareRoot WideSquareRoot
- #else
- */
- ODSShort ODWideCompare( const ODWide*, const ODWide* );
- ODWide* ODWideNegate( ODWide* );
- ODWide* ODWideShift( ODWide*, ODSShort bits ); // Positive is toward MSB
- ODWide* ODWideAdd( ODWide*, const ODWide* );
- ODWide* ODWideSubtract( ODWide*, const ODWide* );
-
- ODSLong ODWideDivide( const ODWide *dividend,
- ODSLong divisor, ODSLong *remainder);
- ODULong ODWideSquareRoot( const ODWide *src );
- /*
- #endif
- */
- #define kODIgnoreRemainder ((ODSLong*)-1L) // Use as remainder in ODWideDivide
-
- #define ODWideIsLong(w) ((w)->hi == 0 && (long)(w)->lo >= 0 || \
- (w)->hi == -1 && (long)(w)->lo < 0)
-
- ODFract ODFractSinCos( ODFixed radians, ODFract *cos ); // returns sin
-
- ODSShort ODFirstBit( ODSLong ); // Returns index (0-32) of 1st bit
-
-
- } // End of extern "C" {
-
- #endif /*_ODMATH_*/
-