MiniGUI API Reference (MiniGUI-Standalone)  v3.2.0
A mature and proven cross-platform GUI system for embedded and smart IoT devices
Functions
Fixed point math functions

Functions

MG_EXPORT fixed fixsqrt (fixed x)
 Returns the non-negative square root of a fixed point value. More...
 
MG_EXPORT fixed fixhypot (fixed x, fixed y)
 Returns the Euclidean distance from the origin. More...
 
MG_EXPORT fixed fixatan (fixed x)
 Calculates the arc tangent of a fixed point value. More...
 
MG_EXPORT fixed fixatan2 (fixed y, fixed x)
 Calculates the arc tangent of two fixed point variables. More...
 
static fixed ftofix (double x)
 Converts a float point value to a fixed point value. More...
 
static double fixtof (fixed x)
 Converts a fixed point value to a float point value. More...
 
static fixed fixadd (fixed x, fixed y)
 Returns the sum of two fixed point values. More...
 
static fixed fixsub (fixed x, fixed y)
 Subtract a fixed point value from another. More...
 
MG_EXPORT fixed fixmul (fixed x, fixed y)
 Returns the product of two fixed point values. More...
 
MG_EXPORT fixed fixdiv (fixed x, fixed y)
 Returns the quotient of two fixed point values. More...
 
static int fixceil (fixed x)
 Rounds a fixed point value to the nearest integer. More...
 
static fixed itofix (int x)
 Converts an integer to a fixed point value. More...
 
static int fixtoi (fixed x)
 Converts an fixed point value to an integer. More...
 
static fixed fixcos (fixed x)
 Returns the cosine of a fixed point. More...
 
static fixed fixsin (fixed x)
 Returns the sine of a fixed point. More...
 
static fixed fixtan (fixed x)
 Returns the tangent of a fixed point. More...
 
static fixed fixacos (fixed x)
 Calculates and returns the arc cosine of a fixed point. More...
 
static fixed fixasin (fixed x)
 Calculates and returns the arc sine of a fixed point. More...
 

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)
inlinestatic

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 411 of file fixedmath.h.

fixed fixadd ( fixed  x,
fixed  y 
)
inlinestatic

Returns the sum of two fixed point values.

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

Parameters
xx,y: Two addends.
yx,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 217 of file fixedmath.h.

fixed fixasin ( fixed  x)
inlinestatic

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 434 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)
inlinestatic

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 316 of file fixedmath.h.

fixed fixcos ( fixed  x)
inlinestatic

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 365 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
xThe dividend.
yThe divisor.
Returns
The quotient. If the result runs out of range of fixed point, this function sets errno to ERANGE.
See also
fixmul

Referenced by fixsub().

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
xThe faciend.
yThe multiplicato.
Returns
The prodcut. If the result runs out of range of fixed point, this function sets errno to ERANGE.
See also
fixdiv

Referenced by fixsub().

fixed fixsin ( fixed  x)
inlinestatic

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 379 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 
)
inlinestatic

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
xThe minuend.
yThe 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 254 of file fixedmath.h.

References fixdiv(), and fixmul().

fixed fixtan ( fixed  x)
inlinestatic

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 393 of file fixedmath.h.

double fixtof ( fixed  x)
inlinestatic

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 197 of file fixedmath.h.

int fixtoi ( fixed  x)
inlinestatic

Converts an fixed point value to an integer.

This function converts the fixed point x to an integer.

See also
itofix

Definition at line 351 of file fixedmath.h.

fixed ftofix ( double  x)
inlinestatic

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 173 of file fixedmath.h.

fixed itofix ( int  x)
inlinestatic

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 338 of file fixedmath.h.