1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** GUIX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Utility (Utility) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "gx_api.h" |
28 |
|
|
#include "gx_utility.h" |
29 |
|
|
|
30 |
|
|
/* define the the table of arc sine values. |
31 |
|
|
The values have been enlarged by 256. */ |
32 |
|
|
static GX_CONST GX_UBYTE asin_angle_value_table[] = { |
33 |
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, |
34 |
|
|
0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06, |
35 |
|
|
0x07, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a, |
36 |
|
|
0x0a, 0x0b, 0x0b, 0x0b, 0x0b, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0d, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e, |
37 |
|
|
0x0e, 0x0e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11, 0x12, |
38 |
|
|
0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15, |
39 |
|
|
0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17, 0x18, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x19, |
40 |
|
|
0x1a, 0x1a, 0x1a, 0x1a, 0x1b, 0x1b, 0x1b, 0x1b, 0x1c, 0x1c, 0x1c, 0x1c, 0x1d, 0x1d, 0x1d, 0x1d, |
41 |
|
|
0x1e, 0x1e, 0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x21, 0x21, 0x21, 0x21, 0x22, |
42 |
|
|
0x22, 0x22, 0x22, 0x23, 0x23, 0x23, 0x24, 0x24, 0x24, 0x24, 0x25, 0x25, 0x25, 0x26, 0x26, 0x26, |
43 |
|
|
0x26, 0x27, 0x27, 0x27, 0x28, 0x28, 0x28, 0x28, 0x29, 0x29, 0x29, 0x2a, 0x2a, 0x2a, 0x2b, 0x2b, |
44 |
|
|
0x2b, 0x2b, 0x2c, 0x2c, 0x2c, 0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f, 0x2f, 0x30, 0x30, |
45 |
|
|
0x30, 0x31, 0x31, 0x31, 0x32, 0x32, 0x32, 0x33, 0x33, 0x34, 0x34, 0x34, 0x35, 0x35, 0x35, 0x36, |
46 |
|
|
0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3b, 0x3b, 0x3c, 0x3c, 0x3d, |
47 |
|
|
0x3d, 0x3d, 0x3e, 0x3e, 0x3f, 0x3f, 0x40, 0x40, 0x41, 0x42, 0x42, 0x43, 0x43, 0x44, 0x44, 0x45, |
48 |
|
|
0x46, 0x46, 0x47, 0x48, 0x49, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x51, 0x52, 0x54, 0x5a |
49 |
|
|
}; |
50 |
|
|
|
51 |
|
|
/**************************************************************************/ |
52 |
|
|
/* */ |
53 |
|
|
/* FUNCTION RELEASE */ |
54 |
|
|
/* */ |
55 |
|
|
/* _gx_utility_math_asin_5_4_0 PORTABLE C */ |
56 |
|
|
/* 6.1 */ |
57 |
|
|
/* AUTHOR */ |
58 |
|
|
/* */ |
59 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
60 |
|
|
/* */ |
61 |
|
|
/* DESCRIPTION */ |
62 |
|
|
/* */ |
63 |
|
|
/* This service computes the angle value of the arc sin x, which is an */ |
64 |
|
|
/* old version of _gx_utility_math_asin. */ |
65 |
|
|
/* */ |
66 |
|
|
/* INPUT */ |
67 |
|
|
/* */ |
68 |
|
|
/* x Value whose arc sin is */ |
69 |
|
|
/* computed, in the interval */ |
70 |
|
|
/* [-256, 256]. */ |
71 |
|
|
/* */ |
72 |
|
|
/* OUTPUT */ |
73 |
|
|
/* */ |
74 |
|
|
/* angle Angle value of arc sin of x */ |
75 |
|
|
/* */ |
76 |
|
|
/* CALLS */ |
77 |
|
|
/* */ |
78 |
|
|
/* None */ |
79 |
|
|
/* */ |
80 |
|
|
/* CALLED BY */ |
81 |
|
|
/* */ |
82 |
|
|
/* Application Code */ |
83 |
|
|
/* */ |
84 |
|
|
/**************************************************************************/ |
85 |
|
|
#if defined(GUIX_5_4_0_COMPATIBILITY) |
86 |
|
|
INT _gx_utility_math_asin_5_4_0(INT x) |
87 |
|
|
{ |
88 |
|
|
INT angle = 0; |
89 |
|
|
|
90 |
|
|
if (x == 256) |
91 |
|
|
{ |
92 |
|
|
angle = 90; |
93 |
|
|
} |
94 |
|
|
else if ((x < 256) && (x >= 0)) |
95 |
|
|
{ |
96 |
|
|
angle = asin_angle_value_table[x]; |
97 |
|
|
} |
98 |
|
|
else if ((x > -256) && (x < 0)) |
99 |
|
|
{ |
100 |
|
|
angle = 0 - asin_angle_value_table[x * -1]; |
101 |
|
|
} |
102 |
|
|
else if (x == -256) |
103 |
|
|
{ |
104 |
|
|
angle = -90; |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
return angle; |
108 |
|
|
} |
109 |
|
|
#endif |
110 |
|
|
|
111 |
|
|
/**************************************************************************/ |
112 |
|
|
/* */ |
113 |
|
|
/* FUNCTION RELEASE */ |
114 |
|
|
/* */ |
115 |
|
|
/* _gx_utility_math_asin PORTABLE C */ |
116 |
|
|
/* 6.1 */ |
117 |
|
|
/* AUTHOR */ |
118 |
|
|
/* */ |
119 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
120 |
|
|
/* */ |
121 |
|
|
/* DESCRIPTION */ |
122 |
|
|
/* */ |
123 |
|
|
/* This service computes the angle value of the arc sin x. */ |
124 |
|
|
/* */ |
125 |
|
|
/* INPUT */ |
126 |
|
|
/* */ |
127 |
|
|
/* x Value whose arc sin is */ |
128 |
|
|
/* computed. The value is a */ |
129 |
|
|
/* fixed point math data type, */ |
130 |
|
|
/* call GX_FIXED_VAL_MAKE to do */ |
131 |
|
|
/* type conversion. */ |
132 |
|
|
/* */ |
133 |
|
|
/* OUTPUT */ |
134 |
|
|
/* */ |
135 |
|
|
/* angle Angle value of arc sin of x */ |
136 |
|
|
/* */ |
137 |
|
|
/* CALLS */ |
138 |
|
|
/* */ |
139 |
|
|
/* None */ |
140 |
|
|
/* */ |
141 |
|
|
/* CALLED BY */ |
142 |
|
|
/* */ |
143 |
|
|
/* Application Code */ |
144 |
|
|
/* */ |
145 |
|
|
/**************************************************************************/ |
146 |
|
62 |
INT _gx_utility_math_asin(GX_FIXED_VAL x) |
147 |
|
|
{ |
148 |
|
62 |
INT angle = 0; |
149 |
|
|
|
150 |
|
62 |
x = GX_FIXED_VAL_TO_INT(x << 8); |
151 |
|
|
|
152 |
✓✓ |
62 |
if (x == 256) |
153 |
|
|
{ |
154 |
|
8 |
angle = 90; |
155 |
|
|
} |
156 |
✓✓✓✓
|
54 |
else if ((x < 256) && (x >= 0)) |
157 |
|
|
{ |
158 |
|
44 |
angle = asin_angle_value_table[x]; |
159 |
|
|
} |
160 |
✓✓✓✓
|
10 |
else if ((x > -256) && (x < 0)) |
161 |
|
|
{ |
162 |
|
6 |
angle = 0 - asin_angle_value_table[x * -1]; |
163 |
|
|
} |
164 |
✓✓ |
4 |
else if (x == -256) |
165 |
|
|
{ |
166 |
|
3 |
angle = -90; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
62 |
return angle; |
170 |
|
|
} |
171 |
|
|
|