Fixed point math functions
[Global/general functions]

Functions


Detailed Description

You know that the float point mathematics routines are very expensive. If you do not want precision mathematics result, you can use fixed point. MiniGUI uses a double word (32-bit) integer to represent a fixed point ranged from -32767.0 to 32767.0, and defines some fixed point mathematics routines for your application. Some GDI functions need fixed point math routines, like Arc.

Example 1:

    /* Draw an arc from 0 radians to 1 radians */
    Arc (hdc, 100, 100, 100, 0, itofix (1));

    /* Draw an arc from 0.5 radians to 1.5 radians */
    fixed radian1 = itofix (1);
    fixed radian2 = itofix (2);
    fixed radian05 = fixdiv (radian1, radian2);
    fixed radian15 = fixdiv (fadd (radian1, randian2), radian2);

    Arc (hdc, 100, 100, 100, radian05, radian15);

Example 2:

void draw_arc (HDC hdc, POINT* pts)
{
            int sx = pts [0].x, sy = pts [0].y;
            int dx = pts [1].x - sx, dy = pts [1].y - sy;
            int r = sqrt (dx * dx * 1.0 + dy * dy * 1.0);
            double cos_d = dx * 1.0 / r;
            fixed cos_f = ftofix (cos_d);
            fixed ang1 = fixacos (cos_f);
            int r2;
            fixed ang2;

            if (dy > 0) {
                ang1 = fixsub (0, ang1);
            }

            dx = pts [2].x - sx;
            dy = pts [2].y - sy;
            r2 = sqrt (dx * dx * 1.0 + dy * dy * 1.0);
            cos_d = dx * 1.0 / r2;
            cos_f = ftofix (cos_d);
            ang2 = fixacos (cos_f);
            if (dy > 0) {
                ang2 = fixsub (0, ang2);
            }

            Arc (hdc, sx, sy, r, ang1, ang2);
}

Function Documentation

fixed fixacos ( fixed  x  )  [inline, static]

Calculates and returns the arc cosine of a fixed point.

This function calculates the arc cosine of the fixed point x; that is the value whose cosine is x. If x falls outside the range -1 to 1, this function fails and errno is set to EDOM.

Returns:
Returns the arc cosine in radians and the value is mathematically defined to be between 0 and PI (inclusive).
See also:
fixcos

Definition at line 390 of file fixedmath.h.

fixed fixadd ( fixed  x,
fixed  y 
) [inline, static]

Returns the sum of two fixed point values.

This function adds two fixed point values x and y, and returns the sum.

Parameters:
x x,y: Two addends.
y x,y: Two addends.
Returns:
The sum. If the result runs out of range of fixed point, this function sets errno to ERANGE.
See also:
fixsub

Definition at line 196 of file fixedmath.h.

fixed fixasin ( fixed  x  )  [inline, static]

Calculates and returns the arc sine of a fixed point.

This function calculates the arc sine of the fixed point x; that is the value whose sine is x. If x falls outside the range -1 to 1, this function fails and errno is set to EDOM.

Returns:
Returns the arc sine in radians and the value is mathematically defined to be between -PI/2 and PI/2 (inclusive).
See also:
fixsin

Definition at line 413 of file fixedmath.h.

fixed fixatan ( fixed  x  ) 

Calculates the arc tangent of a fixed point value.

This function calculates the arc tangent of x; that is the value whose tangent is x.

Returns:
Returns the arc tangent in radians and the value is mathematically defined to be between -PI/2 and PI/2 (inclusive).
See also:
fixatan2
fixed fixatan2 ( fixed  y,
fixed  x 
)

Calculates the arc tangent of two fixed point variables.

This function calculates the arc tangent of the two variables x and y. It is similar to calculating the arc tangent of y / x, except that the signs of both arguments are used to determine the quadrant of the result.

Returns:
Returns the result in radians, which is between -PI and PI (inclusive).
See also:
fixatan
int fixceil ( fixed  x  )  [inline, static]

Rounds a fixed point value to the nearest integer.

This function rounds the fixed point value x to the nearest integer and returns it.

Returns:
The rounded integer value.

Definition at line 295 of file fixedmath.h.

fixed fixcos ( fixed  x  )  [inline, static]

Returns the cosine of a fixed point.

This function returns the cosine of the fixed point x, where x is given in radians.

See also:
fixacos

Definition at line 344 of file fixedmath.h.

fixed fixdiv ( fixed  x,
fixed  y 
)

Returns the quotient of two fixed point values.

This function returns the quotient of two fixed point values x and y.

Parameters:
x The dividend.
y The divisor.
Returns:
The quotient. If the result runs out of range of fixed point, this function sets errno to ERANGE.
See also:
fixmul
fixed fixhypot ( fixed  x,
fixed  y 
)

Returns the Euclidean distance from the origin.

The function returns the sqrt(x*x+y*y). This is the length of the hypotenuse of a right-angle triangle with sides of length x and y, or the distance of the point (x,y) from the origin.

See also:
fixsqrt
fixed fixmul ( fixed  x,
fixed  y 
)

Returns the product of two fixed point values.

This function returns the product of two fixed point values x and y.

Parameters:
x The faciend.
y The multiplicato.
Returns:
The prodcut. If the result runs out of range of fixed point, this function sets errno to ERANGE.
See also:
fixdiv
fixed fixsin ( fixed  x  )  [inline, static]

Returns the sine of a fixed point.

This function returns the sine of the fixed point x, where x is given in radians.

See also:
fixasin

Definition at line 358 of file fixedmath.h.

fixed fixsqrt ( fixed  x  ) 

Returns the non-negative square root of a fixed point value.

This function returns the non-negative square root of x. It fails and sets errno to EDOM, if x is negative.

See also:
fixhypot
fixed fixsub ( fixed  x,
fixed  y 
) [inline, static]

Subtract a fixed point value from another.

This function subtracts the fixed point values y from the fixed point value x, and returns the difference.

Parameters:
x The minuend.
y The subtrahend.
Returns:
The difference. If the result runs out of range of fixed point, this function sets errno to ERANGE.
See also:
fixadd

Definition at line 233 of file fixedmath.h.

fixed fixtan ( fixed  x  )  [inline, static]

Returns the tangent of a fixed point.

This function returns the tangent of the fixed point x, where x is given in radians.

See also:
fixcos, fixsin

Definition at line 372 of file fixedmath.h.

double fixtof ( fixed  x  )  [inline, static]

Converts a fixed point value to a float point value.

This function converts the specified fixed point value x to a float point value.

See also:
ftofix

Definition at line 176 of file fixedmath.h.

int fixtoi ( fixed  x  )  [inline, static]

Converts an fixed point value to an integer.

This function converts the fixed point x to an integer.

See also:
itofix

Definition at line 330 of file fixedmath.h.

fixed ftofix ( double  x  )  [inline, static]

Converts a float point value to a fixed point value.

This function converts the specified float point value x to a fixed point value.

Note:
The float point should be ranged from -32767.0 to 32767.0. If it runs out of the range, this function sets errno to ERANGE.
See also:
fixtof

Definition at line 152 of file fixedmath.h.

fixed itofix ( int  x  )  [inline, static]

Converts an integer to a fixed point value.

This function converts the integer x to a fixed point value.

See also:
fixtoi

Definition at line 317 of file fixedmath.h.

Generated on Thu Apr 7 15:58:37 2011 for MiniGUI V3.0.12 API Reference by  doxygen 1.6.3