Fix Class Reference
[Maths - 32bit Fixed-Point Maths]

Fixed point arithmetic functions. More...

#include <fix.h>

List of all members.

Static Public Member Functions

static fix Add (fix a, fix b)
static fix Sub (fix a, fix b)
static fix Mul (fix a, fix b)
static fix MulNS (fix a, fix b)
static fix Div (fix a, fix b)
static fix Sqrt (ufix a)
static fix Log2 (ufix a)
static ufix Exp2 (fix a)
static fix Sin (fixangle angle)
static fix Cos (fixangle angle)
static fix Tan (fixangle angle)
static fixangle ASin (fix value)
static fixangle ACos (fix value)
static fixangle ATan (fix value)
static fix Random (uint32_t &seed)
static ufix Random (uint32_t &seed, ufix range)

Detailed Description

Fixed point arithmetic functions.

Operands are 32 bits in size with the binary point between bits 15 and 16.

See also:
fix ufix fixangle
Version:
2005-02-26

Definition at line 160 of file fix.h.


Member Function Documentation

fix Fix::Add ( fix  a,
fix  b 
) [static]

Add two fixed-point numbers. Produces saturated result on overflow.

When the addition of two numbers is know not to cause overflow, or when this doesn't matter, normal integer addition (+) can be used instead...

    fix a;
    fix b;
    fix sum = a+b;
Parameters:
a Augend
b Addend
Returns:
a+b.
If a+b>0x7FFF.FFFF then 0x7FFF.FFFF is returned.
If a+b<-0x8000.0000 then -0x8000.0000 is returned.

Definition at line 99 of file fix.cpp.

fix Fix::Sub ( fix  a,
fix  b 
) [static]

Subtract two fixed-point numbers. Produces saturated result on overflow.

When the subtraction of two numbers is know not to cause overflow, or when this doesn't matter, normal integer subtraction (-) can be used instead...

    fix a;
    fix b;
    fix difference = a-b;
Parameters:
a Minuend
b Subtrahend
Returns:
a-b.
If a-b>0x7FFF.FFFF then 0x7FFF.FFFF is returned.
If a-b<-0x8000.0000 then -0x8000.0000 is returned.

Definition at line 108 of file fix.cpp.

fix Fix::Mul ( fix  a,
fix  b 
) [static]

Multiply two fixed-point numbers. Produces saturated result on overflow.

To multiply a fixed point number by an integer, normal integer multiplication (*) may be used...

    fix a;
    fix twoTimes = a*2;

This does not detect overflow.

Parameters:
a Multiplicand
b Multiplier
Returns:
a*b.
If a*b>0x7FFF.FFFF then 0x7FFF.FFFF is returned.
If a*b<-0x8000.0000 then -0x8000.0000 is returned.
See also:
MulNS()

Definition at line 117 of file fix.cpp.

fix Fix::MulNS ( fix  a,
fix  b 
) [static]

Multiply two fixed-point numbers. This is a Non-Saturating (and faster) version of Mul(). On overflow the result is undefined.

To multiply a fixed point number by an integer, normal integer multiplication (*) may be used...

    fix a;
    fix twoTimes = a*2;
Parameters:
a Multiplicand
b Multiplier
Returns:
a*b.
If a*b>0x7FFF.FFFF or a*b<-0x8000.0000 then the returned result is undefined.

Definition at line 183 of file fix.cpp.

fix Fix::Div ( fix  a,
fix  b 
) [static]

Divide two fixed-point numbers. Produces saturated result on overflow. Division by zero is treated as division by a very small number and produces a saturated result accordingly.

To divide a fixed point number by an integer, normal integer division (/) may be used...

    fix a;
    fix half = a/2;

This does not error conditions.

Parameters:
a Dividend
b Divisor
Returns:
a/b.
If a/b>0x7FFF.FFFF then 0x7FFF.FFFF is returned.
If a/b<-0x8000.0000 then -0x8000.0000 is returned.
If b==0 and a>=0 then 0x7FFF.FFFF is returned.
If b==0 and a<0 then -0x8000.0000 is returned.

Definition at line 204 of file fix.cpp.

fix Fix::Sqrt ( ufix  a  )  [static]

Calculate the square root of a fixed-point number.

Parameters:
a Unsigned fixed point number.
Returns:
a^0.5.

Definition at line 379 of file fix.cpp.

fix Fix::Log2 ( ufix  a  )  [static]

Calculate the logarithm to base 2 of a fixed-point number . Accuracy is +/-8.40e-6 (+/-0.55 lsb).

Parameters:
a Unsigned fixed point number.
Returns:
log2(a).
If a==0 then -0x8000.0000 is returned

Definition at line 441 of file fix.cpp.

ufix Fix::Exp2 ( fix  a  )  [static]

Raise 2 to-the-power of a fixed-point number, (2^a). Accuracy is +/-1.14e-5 (+/-0.75 lsb).

Parameters:
a Fixed point number.
Returns:
2^a.
If 2^a>0xFFFF.FFFF then 0xFFFF.FFFF is returned.

Definition at line 490 of file fix.cpp.

fix Fix::Sin ( fixangle  angle  )  [static]

Calculate the Sine of an angle. Accuracy is +/-8.55e-6 (+/-0.56 lsb).

Parameters:
angle The angle.
Returns:
The Sine of angle.

Definition at line 623 of file fix.cpp.

fix Fix::Cos ( fixangle  angle  )  [static]

Calculate the Cosine of an angle. Accuracy is +/-8.55e-6 (+/-0.56 lsb).

Parameters:
angle The angle.
Returns:
The Cosine of angle.

Definition at line 617 of file fix.cpp.

fix Fix::Tan ( fixangle  angle  )  [static]

Calculate the Tangent of an angle. Accuracy is +/-1.01e-5 (+/-0.66 lsb).

Parameters:
angle The angle.
Returns:
The Tangent of angle.
If Tan(angle)>0x7FFF.FFFF then 0x7FFF.FFFF is returned.
If Tan(angle)<-0x8000.0000 then -0x8000.0000 is returned.

Definition at line 653 of file fix.cpp.

fixangle Fix::ASin ( fix  value  )  [static]

Calculate the Arc-Sine of a value. Accuracy is +/-8.55e-6 (+/-0.56 lsb).

Parameters:
value The value. Should be in the range -1.0 to 1.0 (-0x10000 to 0x10000).
Returns:
The Arc-Sine of value.
If value<-1.0 then -0.25 (-0x4000) is returned.
If value>1.0 then 0.25 (0x4000) is returned.

Definition at line 836 of file fix.cpp.

fixangle Fix::ACos ( fix  value  )  [static]

Calculate the Arc-Cosine of a value. Accuracy is +/-8.55e-6 (+/-0.56 lsb).

Parameters:
value The value. Should be in the range -1.0 to 1.0 (-0x10000 to 0x10000).
Returns:
The Arc-Cosine of value.
If value<-1.0 then 0.5 (0x8000) is returned.
If value>1.0 then 0.0 (0x0000) is returned.

Definition at line 826 of file fix.cpp.

fixangle Fix::ATan ( fix  value  )  [static]

Calculate the Arc-Tangent of a value. Accuracy is +/-9.00e-6 (+/-0.59 lsb).

Parameters:
value The value.
Returns:
The Arc-Tangent of value.

Definition at line 919 of file fix.cpp.

fix Fix::Random ( uint32_t seed  )  [static]

Generate a psuedo-random number.

Parameters:
seed A reference to the seed value. This will be updated after each call to this function.
Returns:
A pseudo-random number
Since:
2005-02-26

Definition at line 958 of file fix.cpp.

ufix Fix::Random ( uint32_t seed,
ufix  range 
) [static]

Generate a psuedo-random number.

Parameters:
seed A reference to the seed value. This will be updated after each call to this function.
range The range for the generated numbers.
Returns:
A pseudo-random number less than the value of range
Since:
2005-02-26

Definition at line 964 of file fix.cpp.


The documentation for this class was generated from the following files:

Generated by  doxygen 1.6.1