Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Operating System Utilities /
Chapter 3 - Mathematical and Logical Utilities


Summary of the Mathematical and Logical Utilities

Pascal Summary

Data Types

TYPE
   Fixed          = LongInt;        {fixed-point number}
   Fract          = LongInt;        {fractional number}
   Int64Bit =                       {64-bit integer record}
   RECORD
      hiLong:     LongInt;          {high-order long integer}
      loLong:     LongInt;          {low-order long integer}
   END;

Routines

Testing and Setting Bits

FUNCTION BitTst		(bytePtr: Ptr; bitNum: LongInt): Boolean;
PROCEDURE BitSet	(bytePtr: Ptr; bitNum: LongInt);
PROCEDURE BitClr	(bytePtr: Ptr; bitNum: LongInt);

Performing Logical Operations

FUNCTION BitAnd		(value1, value2: LongInt): LongInt;
FUNCTION BitOr		(value1, value2: LongInt): LongInt;
FUNCTION BitXor		(value1, value2: LongInt): LongInt;
FUNCTION BitNot		(value: LongInt): LongInt;
FUNCTION BitShift	(value: LongInt; count: Integer): LongInt;

Getting and Setting Memory Values

FUNCTION HiWord		(x: LongInt): Integer;
FUNCTION LoWord		(x: LongInt): Integer;
PROCEDURE StuffHex	(thingPtr: Ptr; s: Str255);

Compressing and Decompressing Data

PROCEDURE PackBits	(VAR srcPtr, dstPtr: Ptr; srcBytes: Integer);
PROCEDURE UnpackBits	(VAR srcPtr, dstPtr: Ptr; dstBytes: Integer);

Obtaining a Pseudorandom Number

FUNCTION Random: Integer;

Converting Between Angle and Slope Values

FUNCTION SlopeFromAngle	(angle: Integer): Fixed;
FUNCTION AngleFromSlope	(slope: Fixed): Integer;

Multiplying and Dividing Fixed-Point Numbers

FUNCTION FixMul		(a, b: Fixed): Fixed;
FUNCTION FixDiv		(a, b: Fixed): Fixed;
FUNCTION FracMul	(a, b: Fract): Fract;
FUNCTION FracDiv	(a, b: Fract): Fract;

Performing Calculations on Fixed-Point Numbers

FUNCTION FracSqrt	(x: Fract): Fract;
FUNCTION FracCos	(x: Fixed): Fract;
FUNCTION FracSin	(x: Fixed): Fract;
FUNCTION FixATan2	(x, y: LongInt): Fixed;

Converting Among 32-Bit Numeric Types

FUNCTION Long2Fix	(x: LongInt): Fixed;
FUNCTION Fix2Long	(x: Fixed): LongInt;
FUNCTION Fix2Frac	(x: Fixed): Fract;
FUNCTION Frac2Fix	(x: Fract): Fixed;

Converting Between Fixed-Point and Floating-Point Values

FUNCTION Fix2X		(x: Fixed): Extended;
FUNCTION X2Fix		(x: Extended): Fixed;
FUNCTION Frac2X		(x: Fract): Extended;
FUNCTION X2Frac		(x: Extended): Fract;

Converting Between Fixed-Point and Integral Values

FUNCTION FixRatio	(numer, denom: Integer): Fixed;
FUNCTION FixRound	(x: Fixed): Integer;

Multiplying 32-bit Values

Procedure LongMul	(a, b: LongInt; VAR result: Int64Bit);

C Summary

Data Types

typedef long Fixed;                    /*fixed-point number*/
typedef long Fract;                    /*fractional number*/
struct Int64Bit {                      /*64-bit integer record*/
   long hiLong;                        /*high-order long integer*/
   long loLong;                        /*low-order long integer*/
};
typedef struct Int64Bit Int64Bit;

Routines

Testing and Setting Bits

pascal Boolean BitTst	(const void *bytePtr, long bitNum);
pascal void BitSet	(void *bytePtr, long bitNum);
pascal void BitClr	(void *bytePtr, long bitNum);

Performing Logical Operations

pascal long BitAnd	(long value1, long value2);
pascal long BitOr	(long value1, long value2);
pascal long BitXor	(long value1, long value2);
pascal long BitNot	(long value);
pascal long BitShift	(long value, short count);

Getting and Setting Memory Values

pascal short HiWord	(long x);
pascal short LoWord	(long x);
pascal void StuffHex	(void *thingPtr, ConstStr255Param s);

Compressing and Decompressing Data

pascal void PackBits	(Ptr *srcPtr, Ptr *dstPtr, short srcBytes);
pascal void UnpackBits	(Ptr *srcPtr, Ptr *dstPtr, short dstBytes);

Obtaining a Pseudorandom Number

pascal short Random	(void);

Converting Between Angle and Slope Values

pascal Fixed SlopeFromAngle
			(short angle);
pascal short AngleFromSlope
			(Fixed slope);

Multiplying and Dividing Fixed-Point Numbers

pascal Fixed FixMul	(Fixed a, Fixed b);
pascal Fixed FixDiv	(Fixed a, Fixed b);
pascal Fract FracMul	(Fract a, Fract b);
pascal Fract FracDiv	(Fract a, Fract b);

Performing Calculations with Fixed-Point Numbers

pascal Fract FracSqrt	(Fract x);
pascal Fract FracCos	(Fixed x);
pascal Fract FracSin	(Fixed x);
pascal Fixed FixATan2	(long x, long y);

Converting Among 32-Bit Numeric Types

pascal Fixed Long2Fix	(long x);
pascal long Fix2Long	(Fixed x);
pascal Fract Fix2Frac	(Fixed x);
pascal Fixed Frac2Fix	(Fract x);

Converting Between Fixed-Point and Floating-Point Values

pascal Extended Fix2X	(Fixed x);
pascal Fixed X2Fix	(Extended x);
pascal Extended Frac2X	(Fract x);
pascal Fract X2Frac	(Extended x);

Converting Between Fixed-Point and Integral Values

pascal Fixed FixRatio	(short numer, short denom);
pascal short FixRound	(Fixed x);
Multiplying 32-bit values
Pascal void LongMul	(long a, long b, Int64Bit *result);

Global Variables
randSeed The seed to the pseudorandom number generator.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996