iul_x_math.h
2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*****************************************************************************
*
* Filename:
* ---------
* iul_x_math.h
*
* Project:
* --------
* MAUI
*
* Description:
* ------------
* Image Utility Lirary: fixed-point math libary
*
* Author:
* -------
* -------
*
*============================================================================
* HISTORY
* Below this line, this part is controlled by ClearCase. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* $Log$
*
* 11 23 2010 robin.huang
* removed!
* .remove include iul_gl_x_math.h
*
* 11 23 2010 robin.huang
* removed!
* .
*
* 09 01 2010 robin.huang
* removed!
* .
*
* removed!
* removed!
* Initial version.
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by ClearCase. DO NOT MODIFY!!
*============================================================================
****************************************************************************/
#ifndef __IUL_X_MATH_H__
#define __IUL_X_MATH_H__
typedef int IUL_FIXED; ///< Type definition as S15.16 fixed-point
#define IUL_I_TO_X(i) ((i) << 16) ///< Convert from integer to S15.16 fixed-point
#define IUL_X_TO_I(x) (((x) + (1 << 15)) >> 16) ///< Convert from S15.16 fixed-point to integer (round)
#define IUL_X_TO_I_ROUND(x) (((x) + (1 << 15)) >> 16) ///< Convert from S15.16 fixed-point to integer (round)
#define IUL_X_TO_I_CHOP(x) ((x) >> 16) ///< Convert from S15.16 fixed-point to integer (chop)
#define IUL_X_TO_I_CARRY(x) (((x) + 0x0000FFFF) >> 16) ///< Convert from S15.16 fixed-point to integer (carry)
#define IUL_X_FRACTION(x) ((x) & 0x0000FFFF)
#define IUL_X_HALF (1 << 15)
#define IUL_X_TO_F(x) ((float)x / 65536.0)
#define IUL_F_TO_X(x) (IUL_FIXED)((x) * 65536.0)
#define IUL_X_MUL(a, b) (((a) * (b)) >> 16) /// S15.16 fixed-point multiplication, the overflow is not taken into consideration
/// for fixed-point multiplication with overflow checking, please use iul_x_mul(a, b)
/// function prototype declaration
IUL_FIXED iul_x_add(IUL_FIXED a, IUL_FIXED b);
IUL_FIXED iul_x_sub(IUL_FIXED a, IUL_FIXED b);
IUL_FIXED iul_x_mul(IUL_FIXED a, IUL_FIXED b);
IUL_FIXED iul_x_div(IUL_FIXED n, IUL_FIXED d);
IUL_FIXED iul_x_sin(IUL_FIXED angle);
IUL_FIXED iul_x_cos(IUL_FIXED angle);
IUL_FIXED iul_x_sqrt(IUL_FIXED n);
IUL_FIXED iul_x_power(IUL_FIXED base, IUL_FIXED power);
IUL_FIXED iul_x_log2(IUL_FIXED n);
IUL_FIXED iul_x_cos_rad(IUL_FIXED angle); /// [IN] An angle in radians
IUL_FIXED iul_x_sin_rad(IUL_FIXED angle); /// [IN] An angle in radians
#endif /*__IUL_X_MATH_H__*/