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