You.i Engine
YiMath.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_MATH_H_
3 #define _YI_MATH_H_
4 
5 #include "framework/YiPredef.h"
6 #include "YiMathTables.h" //Automatically generated by the "TableMaker" project!!!!!!
7 #include <math.h>
12 
13 //Math Functions
14 #define YI_SIN (float)sin
15 #define YI_COS (float)cos
16 #define YI_FPOW(x, y) pow((float)x, (float)y)
17 #define YI_SQRT(x) sqrt(x)
18 
19 
20 
21 /*****************************************************************************
22  Fix point functions.
23 ****************************************************************************/
24 #define YI_ITOFXW(x) ((x) << 16) // Integer to fixed point
25 #define YI_FXTOIW(x) ((x) >> 16) // Fixed point to integer
26 #define YI_DIVFXW(x,y) ((y << 16) / (x)) // Divide a fixed by a fixed
27 #define YI_ITOFX(x) ((x) << 16) // Integer to fixed point
28 #define YI_FTOFX(x) (int32_t)((x)*65536) // Float to fixed point
29 #define YI_DTOFX(x) (int32_t)((x)*65536) // Double to fixed point
30 #define YI_FXTOI(x) ((x) >> 16) // Fixed point to integer
31 #define YI_FXTOF(x) ((float)(x) / 65536) // Fixed point to float
32 #define YI_FXTOD(x) ((double)(x) / 65536) // Fixed point to double
33 #define YI_MULFX(x,y) (((y) * (x)) >> 16) // Multiply a fixed by a fixed
34 #define YI_MULFX2(x,y) ((((y)>> 16) * ((x)>> 16))) // Multiply a fixed by a fixed
35 #define YI_DIVFX(x,y) (((x) << 16) / (y)) // Divide a fixed by a fixed
36 
37 /*****************************************************************************
38  Trigonometry tables.
39 ****************************************************************************/
40 extern const int32_t YI_ANGLESHIFT; // YI_ANGLE2PI = 1 << YI_ANGLESHIFT
41 extern const int32_t YI_ANGLE2PI; // equivalent to 2*PI
42 extern const int32_t YI_ANGLEMASK; // angle mask use to acces trigonometric tables
43 extern const float YI_PI; // cherry pie!
44 extern const int32_t YI_TRIG_SHIFT; // shifted 2^n value for sinus/cosinus result
45 extern const int32_t YI_TRIG_MUL; // sinus/cosinus YI_MAX value (==1)
46 extern const int32_t YI_ATAN_SIZE;
47 extern const int16_t g_sYISine[YI_ANGLE2PI];
48 extern const int16_t g_sYICosine[YI_ANGLE2PI];
49 extern const uint16_t g_usYIArctan[YI_ATAN_SIZE + 1];
50 extern const uint16_t g_usYISqrt[256 * 16];
51 
52 #if 1
53 //this is faster, but won't work as expected if x is a calculation such as (s++)
54 #define YI_ABS(x) (((x) < 0) ? -(x) : (x))
55 #define YI_FABS(x) (((x) < 0) ? -(x) : (x))
56 #define YI_DABS(x) (((x) < 0) ? -(x) : (x))
57 #define YI_SGN(x) (((x) > 0 ) ? 1 : ((x) < 0) ? -1 : 0)
58 #define YI_FSGN(x) (((x) > 0 ) ? 1 : ((x) < 0) ? -1 : 0)
59 #define YI_SGN2(x, y) (((x) > y ) ? 1 : ((x) < y) ? -1 : 0)
60 #else
61 YI_EXTERNINLINE int32_t YI_ABS(int32_t x);
62 YI_EXTERNINLINE float YI_FABS(float x);
63 YI_EXTERNINLINE double YI_DABS(double x);
64 YI_EXTERNINLINE int32_t YI_SGN(int32_t x);
65 YI_EXTERNINLINE float YI_FSGN(float x);
66 YI_EXTERNINLINE int32_t YI_SGN2(int32_t x, int32_t y);
67 #endif
68 YI_EXTERNINLINE int32_t YI_FLOOR(float fVal);
69 YI_EXTERNINLINE int32_t YI_FLOOR(double fVal);
70 YI_EXTERNINLINE int32_t YI_CEIL(float fVal);
71 YI_EXTERNINLINE int32_t YI_CEIL(double fVal);
72 YI_EXTERNINLINE int32_t YI_ROUND(float fval);
73 YI_EXTERNINLINE int32_t YI_ROUND(double fval);
74 YI_EXTERNINLINE int32_t YI_DIFF(int32_t x, int32_t y);
75 
76 int32_t Log2(int32_t a);
77 int32_t Atan2i(int32_t y, int32_t x);
78 int32_t AngleDiff(int32_t SrcAngle, int32_t TargetAngle);
79 int32_t YI_INTSQRT(int32_t l2);
80 int32_t YI_INTSQRT256(int32_t l2);
81 int32_t YI_POW(int32_t P, int32_t z);
82 
85 #endif // _YI_MATH_H_
const int32_t YI_ATAN_SIZE
Definition: YiMathTables.h:21
#define YI_SGN(x)
Definition: YiMath.h:57
int32_t YI_INTSQRT256(int32_t l2)
#define YI_EXTERNINLINE
Definition: YiPredef.h:74
const int32_t YI_ANGLE2PI
Definition: YiMathTables.h:15
YI_EXTERNINLINE int32_t YI_ROUND(float fval)
int32_t YI_INTSQRT(int32_t l2)
#define YI_DABS(x)
Definition: YiMath.h:56
int32_t Log2(int32_t a)
#define YI_FSGN(x)
Definition: YiMath.h:58
const int16_t g_sYICosine[YI_ANGLE2PI]
Definition: YiMathTables.h:118
const float YI_PI
Definition: YiMathTables.h:18
YI_EXTERNINLINE int32_t YI_FLOOR(float fVal)
int32_t YI_POW(int32_t P, int32_t z)
YI_EXTERNINLINE int32_t YI_DIFF(int32_t x, int32_t y)
const int32_t YI_TRIG_SHIFT
Definition: YiMathTables.h:19
int32_t AngleDiff(int32_t SrcAngle, int32_t TargetAngle)
const int32_t YI_ANGLEMASK
Definition: YiMathTables.h:17
int32_t Atan2i(int32_t y, int32_t x)
const uint16_t g_usYIArctan[YI_ATAN_SIZE+1]
Definition: YiMathTables.h:213
const int32_t YI_TRIG_MUL
Definition: YiMathTables.h:20
const int32_t YI_ANGLESHIFT
Definition: YiMathTables.h:14
#define YI_FABS(x)
Definition: YiMath.h:55
#define YI_ABS(x)
Definition: YiMath.h:54
YI_EXTERNINLINE int32_t YI_CEIL(float fVal)
#define YI_SGN2(x, y)
Definition: YiMath.h:59
const int16_t g_sYISine[YI_ANGLE2PI]
Definition: YiMathTables.h:23
const uint16_t g_usYISqrt[256 *16]
Definition: YiMathTables.h:238