Mac OS 9
FixMath.h File Reference

Fixed Math Interfaces. More...

#include <MacTypes.h>

Go to the source code of this file.

Macros

#define fixed1   ((Fixed)0x00010000L)
 
#define fract1   ((Fract)0x40000000L)
 
#define positiveInfinity   ((long)0x7FFFFFFFL)
 
#define negativeInfinity   ((long)0x80000000L)
 

Functions

Fixed FixRatio (short numer, short denom)
 
Fixed FixMul (Fixed a, Fixed b)
 
short FixRound (Fixed x)
 
Fract Fix2Frac (Fixed x)
 
long Fix2Long (Fixed x)
 
Fixed Long2Fix (long x)
 
Fixed Frac2Fix (Fract x)
 
Fract FracMul (Fract x, Fract y)
 
Fixed FixDiv (Fixed x, Fixed y)
 
Fract FracDiv (Fract x, Fract y)
 
Fract FracSqrt (Fract x)
 
Fract FracSin (Fixed x)
 
Fract FracCos (Fixed x)
 
Fixed FixATan2 (long x, long y)
 
double Frac2X (Fract x)
 Convert a Fract to an Extended data type. More...
 
double Fix2X (Fixed x)
 Convert a Fixed to an Extended data type. More...
 
Fixed X2Fix (double x)
 Convert an Extended to a Fixed data type. More...
 
Fract X2Frac (double x)
 Convert an Extended to a Fract data type. More...
 
short WideCompare (const wide *target, const wide *source)
 
wideWideAdd (wide *target, const wide *source)
 
wideWideSubtract (wide *target, const wide *source)
 
wideWideNegate (wide *target)
 
wideWideShift (wide *target, long shift)
 
unsigned long WideSquareRoot (const wide *source)
 
wideWideMultiply (long multiplicand, long multiplier, wide *target)
 
long WideDivide (const wide *dividend, long divisor, long *remainder)
 
wideWideWideDivide (wide *dividend, long divisor, long *remainder)
 
wideWideBitShift (wide *src, long shift)
 

Detailed Description

Fixed Math Interfaces.

Introduced In: Mac OS 8
Avaliable From: Universal Interfaces 3.4.1
Copyright: © 1985-2001 by Apple Computer, Inc., all rights reserved

For bug reports, consult the following page on the World Wide Web:

http://developer.apple.com/bugreporter/

Function Documentation

◆ Fix2Frac()

Fract Fix2Frac ( Fixed  x)
\brief Convert a Fixed to a Fract data type

<pre>Fix2Frac returns its Fixed argument, converted into a Fract data type.

argis a 32-bit Fixed value.

Returns
a 32-bit Fract value, equivalent to arg to the best precision
possible for the data type.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ Fix2Long()

long Fix2Long ( Fixed  x)
\brief Convert a Fixed to a long data type

<pre>Fix2Long returns its Fixed argument, converted into a long data type.

argis a 32-bit Fixed value.

Returns
a 32-bit long value, equivalent to arg to the best precision possible
for the data type.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ Fix2X()

double Fix2X ( Fixed  x)

Convert a Fixed to an Extended data type.

Fix2X returns its Fixed argument, converted into an Extended data type.
argis a 32-bit Fixed value.
Returns
a 64-bit double value, equivalent to arg.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FixATan2()

Fixed FixATan2 ( long  x,
long  y 
)
\brief Extract arctangent of the quotient of two 32-bit values

<pre>FixATan2 returns the arctangent quotient of opA / opB in radians.

opAand... opBare two 32-bit values. Both should be the same data type; either long, Fixed, or Fract.

Returns
a 32-bit Fixed value; the arctangent of opA / opB, expressed in
radians.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FixDiv()

Fixed FixDiv ( Fixed  x,
Fixed  y 
)
\brief Divide  one 32-bit quantity by another
\param    opA dividend
Parameters
opBdivisor
FixDiv returns the quotient of opA / opB.
opAand...
opBare two 32-bit values, formatted as any of the data types long,
Fixed, or Fract.
Returns
a 32-bit value whose format depends on that of the input
parameters:
opA opB returned
Fixed/Fixed=Fixed
long/long=Fixed
Fract/Fract=Fixed
long/Fixed=long
Fract/Fixed=Fract
Note
Division by 0 yields 0x7FFFFFFF if opA is positive or 0 and 0x80000000
if opA is negative. Division overflow yields 0x7FFFFFFF for positive
results and 0x80000000 for negative results.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FixMul()

Fixed FixMul ( Fixed  a,
Fixed  b 
)
\brief Get fixed-point product of two integers
\param    a integers to . .
Parameters
b. . . multiply
FixMul performs fixed-point multiplication on two Fixed values, returning
the signed product (MOD 65536) as a 32-bit Fixed data type. Use this to
format the result as a Fixed data type, in case you need that type for
subsequent operations.
aand . . .
bare Fixed values, in the range -32769 to 32767. xxxx
xxxx is 1- (1/65536)
Returns
a 32-bit Fixed value. The high 16 bits are the integer portion; the
low word is always 0.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FixRatio()

Fixed FixRatio ( short  numer,
short  denom 
)

FixRatio, FixMul, and FixRound were previously in ToolUtils.h

\brief Get fixed-point quotient of two integers

<pre>FixRatio performs fixed-point division on two integers, returning the

quotient as a 32-bit Fixed data type. numerand . . . denomare 16-bit signed integers, in the range -32767 to 32767

Returns
a 32-bit Fixed value. The high 16 bits are the integer portion; the
low word is the fractional portion.
Note
This function will happily divide by 0;  if denom is 0, this returns
0x7FFFFFFF when numer is positive or 0x8000001 when numer is
negative.
This is handy for calculating the spacing needed for drawing justified text
(see SpaceExtra ).
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FixRound()

short FixRound ( Fixed  x)
\brief Get nearest short integer to a fixed-point value

<pre>FixRound rounds a positive fixed-point number, returning the value of the

nearest short integer. fixedNum is a 4-byte fixed-point value.The function rounds correctly for positive values only. See Notes, below

Returns
a 16-bit signed integer; the nearest integer to fixedNum . If the
fractional part of fixedNum  is .5, the return value is rounded up to
the next higher integer.
Note
To round a negative fixed-point number correctly (i.e., a larger fraction
being more negative), you should first negate fixedNum , call FixRound ,
then negate the returned integer; e.g.:
FixedunRounded;
shortrounded;
if (unRounded < 0 )
rounded = - FixRound ( -unRounded );
else
rounded = FixRound ( unRounded );
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ Frac2Fix()

Fixed Frac2Fix ( Fract  x)
\brief Convert a Fract to a Fixed data type

<pre>Frac2Fix returns its Fract argument, converted into a Fixed data type.

argis a 32-bit Fract value.

Returns
a 32-bit Fixed value, equivalent to arg to the best precision
possible for the data type.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ Frac2X()

double Frac2X ( Fract  x)

Convert a Fract to an Extended data type.

Frac2X, Fix2X, X2Fix, and X2Frac translate to and from the floating point type "extended" (that's what the X is for). On the original Mac this was 80-bits and the functions could be accessed via A-Traps. When the 68881 co-processor was added, it used 96-bit floating point types, so the A-Traps could not be used. When PowerPC was added, it used 64-bit floating point types, so yet another prototype was added.

Frac2X returns its Fract argument, converted into an Extended data type.
argis a 32-bit Fract value.
Returns
a 64-bit double value, equivalent to arg to the best precision
possible for the data type.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FracCos()

Fract FracCos ( Fixed  x)
\brief Extract cosine of a Fixed, returning a Fract

<pre>FracCos returns the cosine of its radian argument.

argis a 32-bit Fixed data type, expressed in radians.

Returns
a 32-bit Fract value, the cosine of arg.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FracDiv()

Fract FracDiv ( Fract  x,
Fract  y 
)
\brief Divide one 32-bit quantity by another
\param    opA dividend
Parameters
opBdivisor
FracDiv returns the quotient of fracA / fracB.
opAand...
opBare two 32-bit values, formatted as any of the data types long,
Fixed, or Fract.
Returns
a 32-bit value, whose format depends on that of the input
parameters:
opA opB returned
Fract/Fract=Fract
long/long=Fract
Fixed/Fixed=Fract
long/Fract=long
Fixed/Fract=Fixed
Note
Division by 0 yields 0x7FFFFFFF if opA is positive or 0 and 0x80000000
if opA is negative. Division overflow yields 0x7FFFFFFF for positive
results and 0x8000000 for negative results.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FracMul()

Fract FracMul ( Fract  x,
Fract  y 
)
\brief Multiply Fract by Fract, long,  or Fixed
\param    opA multiplicand
Parameters
opBmultiplier
FracMul returns the product of opA * opB.
opAand...
opBare two 32-bit values. At least one of them should be formatted as a
Fract data type.
Returns
a 32-bit value, whose format depends on that of the input
parameters:
opA opB returned
Fract*Fract=Fract
long*Fract=long
Fract*long=long
Fixed*Fract=Fixed
Fract*Fixed=Fixed
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FracSin()

Fract FracSin ( Fixed  x)
\brief Extract sine of a Fixed, returning a Fract

<pre>FracSin returns the sine of its radian argument.

argis a 32-bit Fixed data type, expressed in radians.

Returns
a 32-bit Fract value, the sine of arg.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ FracSqrt()

Fract FracSqrt ( Fract  x)
\brief Extract square root of a Fract, returning a Fract
\param    arg treated as an unsigned Fract, 0...4-(2^-30);
<pre>FracSqrt returns the square root of its positive, fractional argument.

argis a 32-bit unsigned Fract data type.

Returns
a 32-bit Fract value, the square root of arg.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ Long2Fix()

Fixed Long2Fix ( long  x)
\brief Convert a long to a Fixed data type

<pre>Long2Fix returns its long integer argument, converted into a Fixed data

type. argis a 32-bit long value.

Returns
a 32-bit Fixed value, equivalent to arg to the best precision
possible for the data type.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideAdd()

wide* WideAdd ( wide target,
const wide source 
)

WideAdd()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideBitShift()

wide* WideBitShift ( wide src,
long  shift 
)

WideBitShift()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideCompare()

short WideCompare ( const wide target,
const wide source 
)

TARGET_CPU_68K QuickTime 3.0 makes these Wide routines available on other platforms WideCompare()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideDivide()

long WideDivide ( const wide dividend,
long  divisor,
long *  remainder 
)

returns the quotient WideDivide()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideMultiply()

wide* WideMultiply ( long  multiplicand,
long  multiplier,
wide target 
)

WideMultiply()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideNegate()

wide* WideNegate ( wide target)

WideNegate()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideShift()

wide* WideShift ( wide target,
long  shift 
)

WideShift()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideSquareRoot()

unsigned long WideSquareRoot ( const wide source)

WideSquareRoot()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideSubtract()

wide* WideSubtract ( wide target,
const wide source 
)

WideSubtract()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ WideWideDivide()

wide* WideWideDivide ( wide dividend,
long  divisor,
long *  remainder 
)

quotient replaces dividend WideWideDivide()

Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ X2Fix()

Fixed X2Fix ( double  x)

Convert an Extended to a Fixed data type.

X2Fix returns its Extended argument, converted into a Fixed data type.
argis an 80-bit or 96-bit Extended value.
Returns
a 32-bit Fixed value, equivalent to arg to the best precision
possible for the data type.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later

◆ X2Frac()

Fract X2Frac ( double  x)

Convert an Extended to a Fract data type.

X2Frac returns its Extended argument, converted into a Fract data type.
argis an 80-bit or 96-bit Extended value.
Returns
a 32-bit Fract value, equivalent to arg to the best precision
possible for the data type.
Copyright: THINK Reference © 1991-1992 Symantec Corporation
Non-Carbon CFM: in InterfaceLib 7.1 and later
Carbon Lib: in CarbonLib 1.0 and later
Mac OS X: in version 10.0 and later