ReactOS 0.4.15-dev-7934-g1dc8d80
atan2f.c
Go to the documentation of this file.
1
2/*******************************************************************************
3MIT License
4-----------
5
6Copyright (c) 2002-2019 Advanced Micro Devices, Inc.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this Software and associated documentaon files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in
16all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24THE SOFTWARE.
25*******************************************************************************/
26
27#include "libm.h"
28#include "libm_util.h"
29
30#define USE_VALF_WITH_FLAGS
31#define USE_NAN_WITH_FLAGS
32#define USE_SCALEDOUBLE_1
33#define USE_SCALEDOWNDOUBLE
34#define USE_HANDLE_ERRORF
35#include "libm_inlines.h"
36#undef USE_VALF_WITH_FLAGS
37#undef USE_NAN_WITH_FLAGS
38#undef USE_SCALEDOUBLE_1
39#undef USE_SCALEDOWNDOUBLE
40#undef USE_HANDLE_ERRORF
41
42#include "libm_errno.h"
43
44#ifdef _MSC_VER
45// Disable "C4163: not available as intrinsic function" warning that older
46// compilers may issue here.
47#pragma warning(disable:4163)
48#pragma function(atan2f)
49#endif
50
51float FN_PROTOTYPE(atan2f)(float fy, float fx)
52{
53 /* Array atan_jby256 contains precomputed values of atan(j/256),
54 for j = 16, 17, ..., 256. */
55
56 static const double atan_jby256[ 241] = {
57 6.24188099959573430842e-02, /* 0x3faff55bb72cfde9 */
58 6.63088949198234745008e-02, /* 0x3fb0f99ea71d52a6 */
59 7.01969710718705064423e-02, /* 0x3fb1f86dbf082d58 */
60 7.40829225490337306415e-02, /* 0x3fb2f719318a4a9a */
61 7.79666338315423007588e-02, /* 0x3fb3f59f0e7c559d */
62 8.18479898030765457007e-02, /* 0x3fb4f3fd677292fb */
63 8.57268757707448092464e-02, /* 0x3fb5f2324fd2d7b2 */
64 8.96031774848717321724e-02, /* 0x3fb6f03bdcea4b0c */
65 9.34767811585894559112e-02, /* 0x3fb7ee182602f10e */
66 9.73475734872236708739e-02, /* 0x3fb8ebc54478fb28 */
67 1.01215441667466668485e-01, /* 0x3fb9e94153cfdcf1 */
68 1.05080273416329528224e-01, /* 0x3fbae68a71c722b8 */
69 1.08941956989865793015e-01, /* 0x3fbbe39ebe6f07c3 */
70 1.12800381201659388752e-01, /* 0x3fbce07c5c3cca32 */
71 1.16655435441069349478e-01, /* 0x3fbddd21701eba6e */
72 1.20507009691224548087e-01, /* 0x3fbed98c2190043a */
73 1.24354994546761424279e-01, /* 0x3fbfd5ba9aac2f6d */
74 1.28199281231298117811e-01, /* 0x3fc068d584212b3d */
75 1.32039761614638734288e-01, /* 0x3fc0e6adccf40881 */
76 1.35876328229701304195e-01, /* 0x3fc1646541060850 */
77 1.39708874289163620386e-01, /* 0x3fc1e1fafb043726 */
78 1.43537293701821222491e-01, /* 0x3fc25f6e171a535c */
79 1.47361481088651630200e-01, /* 0x3fc2dcbdb2fba1ff */
80 1.51181331798580037562e-01, /* 0x3fc359e8edeb99a3 */
81 1.54996741923940972718e-01, /* 0x3fc3d6eee8c6626c */
82 1.58807608315631065832e-01, /* 0x3fc453cec6092a9e */
83 1.62613828597948567589e-01, /* 0x3fc4d087a9da4f17 */
84 1.66415301183114927586e-01, /* 0x3fc54d18ba11570a */
85 1.70211925285474380276e-01, /* 0x3fc5c9811e3ec269 */
86 1.74003600935367680469e-01, /* 0x3fc645bfffb3aa73 */
87 1.77790228992676047071e-01, /* 0x3fc6c1d4898933d8 */
88 1.81571711160032150945e-01, /* 0x3fc73dbde8a7d201 */
89 1.85347949995694760705e-01, /* 0x3fc7b97b4bce5b02 */
90 1.89118848926083965578e-01, /* 0x3fc8350be398ebc7 */
91 1.92884312257974643856e-01, /* 0x3fc8b06ee2879c28 */
92 1.96644245190344985064e-01, /* 0x3fc92ba37d050271 */
93 2.00398553825878511514e-01, /* 0x3fc9a6a8e96c8626 */
94 2.04147145182116990236e-01, /* 0x3fca217e601081a5 */
95 2.07889927202262986272e-01, /* 0x3fca9c231b403279 */
96 2.11626808765629753628e-01, /* 0x3fcb1696574d780b */
97 2.15357699697738047551e-01, /* 0x3fcb90d7529260a2 */
98 2.19082510780057748701e-01, /* 0x3fcc0ae54d768466 */
99 2.22801153759394493514e-01, /* 0x3fcc84bf8a742e6d */
100 2.26513541356919617664e-01, /* 0x3fccfe654e1d5395 */
101 2.30219587276843717927e-01, /* 0x3fcd77d5df205736 */
102 2.33919206214733416127e-01, /* 0x3fcdf110864c9d9d */
103 2.37612313865471241892e-01, /* 0x3fce6a148e96ec4d */
104 2.41298826930858800743e-01, /* 0x3fcee2e1451d980c */
105 2.44978663126864143473e-01, /* 0x3fcf5b75f92c80dd */
106 2.48651741190513253521e-01, /* 0x3fcfd3d1fc40dbe4 */
107 2.52317980886427151166e-01, /* 0x3fd025fa510665b5 */
108 2.55977303013005474952e-01, /* 0x3fd061eea03d6290 */
109 2.59629629408257511791e-01, /* 0x3fd09dc597d86362 */
110 2.63274882955282396590e-01, /* 0x3fd0d97ee509acb3 */
111 2.66912987587400396539e-01, /* 0x3fd1151a362431c9 */
112 2.70543868292936529052e-01, /* 0x3fd150973a9ce546 */
113 2.74167451119658789338e-01, /* 0x3fd18bf5a30bf178 */
114 2.77783663178873208022e-01, /* 0x3fd1c735212dd883 */
115 2.81392432649178403370e-01, /* 0x3fd2025567e47c95 */
116 2.84993688779881237938e-01, /* 0x3fd23d562b381041 */
117 2.88587361894077354396e-01, /* 0x3fd278372057ef45 */
118 2.92173383391398755471e-01, /* 0x3fd2b2f7fd9b5fe2 */
119 2.95751685750431536626e-01, /* 0x3fd2ed987a823cfe */
120 2.99322202530807379706e-01, /* 0x3fd328184fb58951 */
121 3.02884868374971361060e-01, /* 0x3fd362773707ebcb */
122 3.06439619009630070945e-01, /* 0x3fd39cb4eb76157b */
123 3.09986391246883430384e-01, /* 0x3fd3d6d129271134 */
124 3.13525122985043869228e-01, /* 0x3fd410cbad6c7d32 */
125 3.17055753209146973237e-01, /* 0x3fd44aa436c2af09 */
126 3.20578221991156986359e-01, /* 0x3fd4845a84d0c21b */
127 3.24092470489871664618e-01, /* 0x3fd4bdee586890e6 */
128 3.27598440950530811477e-01, /* 0x3fd4f75f73869978 */
129 3.31096076704132047386e-01, /* 0x3fd530ad9951cd49 */
130 3.34585322166458920545e-01, /* 0x3fd569d88e1b4cd7 */
131 3.38066122836825466713e-01, /* 0x3fd5a2e0175e0f4e */
132 3.41538425296541714449e-01, /* 0x3fd5dbc3fbbe768d */
133 3.45002177207105076295e-01, /* 0x3fd614840309cfe1 */
134 3.48457327308122011278e-01, /* 0x3fd64d1ff635c1c5 */
135 3.51903825414964732676e-01, /* 0x3fd685979f5fa6fd */
136 3.55341622416168290144e-01, /* 0x3fd6bdeac9cbd76c */
137 3.58770670270572189509e-01, /* 0x3fd6f61941e4def0 */
138 3.62190922004212156882e-01, /* 0x3fd72e22d53aa2a9 */
139 3.65602331706966821034e-01, /* 0x3fd7660752817501 */
140 3.69004854528964421068e-01, /* 0x3fd79dc6899118d1 */
141 3.72398446676754202311e-01, /* 0x3fd7d5604b63b3f7 */
142 3.75783065409248884237e-01, /* 0x3fd80cd46a14b1d0 */
143 3.79158669033441808605e-01, /* 0x3fd84422b8df95d7 */
144 3.82525216899905096124e-01, /* 0x3fd87b4b0c1ebedb */
145 3.85882669398073752109e-01, /* 0x3fd8b24d394a1b25 */
146 3.89230987951320717144e-01, /* 0x3fd8e92916f5cde8 */
147 3.92570135011828580396e-01, /* 0x3fd91fde7cd0c662 */
148 3.95900074055262896078e-01, /* 0x3fd9566d43a34907 */
149 3.99220769575252543149e-01, /* 0x3fd98cd5454d6b18 */
150 4.02532187077682512832e-01, /* 0x3fd9c3165cc58107 */
151 4.05834293074804064450e-01, /* 0x3fd9f93066168001 */
152 4.09127055079168300278e-01, /* 0x3fda2f233e5e530b */
153 4.12410441597387267265e-01, /* 0x3fda64eec3cc23fc */
154 4.15684422123729413467e-01, /* 0x3fda9a92d59e98cf */
155 4.18948967133552840902e-01, /* 0x3fdad00f5422058b */
156 4.22204048076583571270e-01, /* 0x3fdb056420ae9343 */
157 4.25449637370042266227e-01, /* 0x3fdb3a911da65c6c */
158 4.28685708391625730496e-01, /* 0x3fdb6f962e737efb */
159 4.31912235472348193799e-01, /* 0x3fdba473378624a5 */
160 4.35129193889246812521e-01, /* 0x3fdbd9281e528191 */
161 4.38336559857957774877e-01, /* 0x3fdc0db4c94ec9ef */
162 4.41534310525166673322e-01, /* 0x3fdc42191ff11eb6 */
163 4.44722423960939305942e-01, /* 0x3fdc76550aad71f8 */
164 4.47900879150937292206e-01, /* 0x3fdcaa6872f3631b */
165 4.51069655988523443568e-01, /* 0x3fdcde53432c1350 */
166 4.54228735266762495559e-01, /* 0x3fdd121566b7f2ad */
167 4.57378098670320809571e-01, /* 0x3fdd45aec9ec862b */
168 4.60517728767271039558e-01, /* 0x3fdd791f5a1226f4 */
169 4.63647609000806093515e-01, /* 0x3fddac670561bb4f */
170 4.66767723680866497560e-01, /* 0x3fdddf85bb026974 */
171 4.69878057975686880265e-01, /* 0x3fde127b6b0744af */
172 4.72978597903265574054e-01, /* 0x3fde4548066cf51a */
173 4.76069330322761219421e-01, /* 0x3fde77eb7f175a34 */
174 4.79150242925822533735e-01, /* 0x3fdeaa65c7cf28c4 */
175 4.82221324227853687105e-01, /* 0x3fdedcb6d43f8434 */
176 4.85282563559221225002e-01, /* 0x3fdf0ede98f393cf */
177 4.88333951056405479729e-01, /* 0x3fdf40dd0b541417 */
178 4.91375477653101910835e-01, /* 0x3fdf72b221a4e495 */
179 4.94407135071275316562e-01, /* 0x3fdfa45dd3029258 */
180 4.97428915812172245392e-01, /* 0x3fdfd5e0175fdf83 */
181 5.00440813147294050189e-01, /* 0x3fe0039c73c1a40b */
182 5.03442821109336358099e-01, /* 0x3fe01c341e82422d */
183 5.06434934483096732549e-01, /* 0x3fe034b709250488 */
184 5.09417148796356245022e-01, /* 0x3fe04d25314342e5 */
185 5.12389460310737621107e-01, /* 0x3fe0657e94db30cf */
186 5.15351866012543347040e-01, /* 0x3fe07dc3324e9b38 */
187 5.18304363603577900044e-01, /* 0x3fe095f30861a58f */
188 5.21246951491958210312e-01, /* 0x3fe0ae0e1639866c */
189 5.24179628782913242802e-01, /* 0x3fe0c6145b5b43da */
190 5.27102395269579471204e-01, /* 0x3fe0de05d7aa6f7c */
191 5.30015251423793132268e-01, /* 0x3fe0f5e28b67e295 */
192 5.32918198386882147055e-01, /* 0x3fe10daa77307a0d */
193 5.35811237960463593311e-01, /* 0x3fe1255d9bfbd2a8 */
194 5.38694372597246617929e-01, /* 0x3fe13cfbfb1b056e */
195 5.41567605391844897333e-01, /* 0x3fe1548596376469 */
196 5.44430940071603086672e-01, /* 0x3fe16bfa6f5137e1 */
197 5.47284380987436924748e-01, /* 0x3fe1835a88be7c13 */
198 5.50127933104692989907e-01, /* 0x3fe19aa5e5299f99 */
199 5.52961601994028217888e-01, /* 0x3fe1b1dc87904284 */
200 5.55785393822313511514e-01, /* 0x3fe1c8fe7341f64f */
201 5.58599315343562330405e-01, /* 0x3fe1e00babdefeb3 */
202 5.61403373889889367732e-01, /* 0x3fe1f7043557138a */
203 5.64197577362497537656e-01, /* 0x3fe20de813e823b1 */
204 5.66981934222700489912e-01, /* 0x3fe224b74c1d192a */
205 5.69756453482978431069e-01, /* 0x3fe23b71e2cc9e6a */
206 5.72521144698072359525e-01, /* 0x3fe25217dd17e501 */
207 5.75276017956117824426e-01, /* 0x3fe268a940696da6 */
208 5.78021083869819540801e-01, /* 0x3fe27f261273d1b3 */
209 5.80756353567670302596e-01, /* 0x3fe2958e59308e30 */
210 5.83481838685214859730e-01, /* 0x3fe2abe21aded073 */
211 5.86197551356360535557e-01, /* 0x3fe2c2215e024465 */
212 5.88903504204738026395e-01, /* 0x3fe2d84c2961e48b */
213 5.91599710335111383941e-01, /* 0x3fe2ee628406cbca */
214 5.94286183324841177367e-01, /* 0x3fe30464753b090a */
215 5.96962937215401501234e-01, /* 0x3fe31a52048874be */
216 5.99629986503951384336e-01, /* 0x3fe3302b39b78856 */
217 6.02287346134964152178e-01, /* 0x3fe345f01cce37bb */
218 6.04935031491913965951e-01, /* 0x3fe35ba0b60eccce */
219 6.07573058389022313541e-01, /* 0x3fe3713d0df6c503 */
220 6.10201443063065118722e-01, /* 0x3fe386c52d3db11e */
221 6.12820202165241245673e-01, /* 0x3fe39c391cd41719 */
222 6.15429352753104952356e-01, /* 0x3fe3b198e5e2564a */
223 6.18028912282561737612e-01, /* 0x3fe3c6e491c78dc4 */
224 6.20618898599929469384e-01, /* 0x3fe3dc1c2a188504 */
225 6.23199329934065904268e-01, /* 0x3fe3f13fb89e96f4 */
226 6.25770224888563042498e-01, /* 0x3fe4064f47569f48 */
227 6.28331602434009650615e-01, /* 0x3fe41b4ae06fea41 */
228 6.30883481900321840818e-01, /* 0x3fe430328e4b26d5 */
229 6.33425882969144482537e-01, /* 0x3fe445065b795b55 */
230 6.35958825666321447834e-01, /* 0x3fe459c652badc7f */
231 6.38482330354437466191e-01, /* 0x3fe46e727efe4715 */
232 6.40996417725432032775e-01, /* 0x3fe4830aeb5f7bfd */
233 6.43501108793284370968e-01, /* 0x3fe4978fa3269ee1 */
234 6.45996424886771558604e-01, /* 0x3fe4ac00b1c71762 */
235 6.48482387642300484032e-01, /* 0x3fe4c05e22de94e4 */
236 6.50959018996812410762e-01, /* 0x3fe4d4a8023414e8 */
237 6.53426341180761927063e-01, /* 0x3fe4e8de5bb6ec04 */
238 6.55884376711170835605e-01, /* 0x3fe4fd013b7dd17e */
239 6.58333148384755983962e-01, /* 0x3fe51110adc5ed81 */
240 6.60772679271132590273e-01, /* 0x3fe5250cbef1e9fa */
241 6.63202992706093175102e-01, /* 0x3fe538f57b89061e */
242 6.65624112284960989250e-01, /* 0x3fe54ccaf0362c8f */
243 6.68036061856020157990e-01, /* 0x3fe5608d29c70c34 */
244 6.70438865514021320458e-01, /* 0x3fe5743c352b33b9 */
245 6.72832547593763097282e-01, /* 0x3fe587d81f732fba */
246 6.75217132663749830535e-01, /* 0x3fe59b60f5cfab9d */
247 6.77592645519925151909e-01, /* 0x3fe5aed6c5909517 */
248 6.79959111179481823228e-01, /* 0x3fe5c2399c244260 */
249 6.82316554874748071313e-01, /* 0x3fe5d58987169b18 */
250 6.84665002047148862907e-01, /* 0x3fe5e8c6941043cf */
251 6.87004478341244895212e-01, /* 0x3fe5fbf0d0d5cc49 */
252 6.89335009598845749323e-01, /* 0x3fe60f084b46e05e */
253 6.91656621853199760075e-01, /* 0x3fe6220d115d7b8d */
254 6.93969341323259825138e-01, /* 0x3fe634ff312d1f3b */
255 6.96273194408023488045e-01, /* 0x3fe647deb8e20b8f */
256 6.98568207680949848637e-01, /* 0x3fe65aabb6c07b02 */
257 7.00854407884450081312e-01, /* 0x3fe66d663923e086 */
258 7.03131821924453670469e-01, /* 0x3fe6800e4e7e2857 */
259 7.05400476865049030906e-01, /* 0x3fe692a40556fb6a */
260 7.07660399923197958039e-01, /* 0x3fe6a5276c4b0575 */
261 7.09911618463524796141e-01, /* 0x3fe6b798920b3d98 */
262 7.12154159993178659249e-01, /* 0x3fe6c9f7855c3198 */
263 7.14388052156768926793e-01, /* 0x3fe6dc44551553ae */
264 7.16613322731374569052e-01, /* 0x3fe6ee7f10204aef */
265 7.18829999621624415873e-01, /* 0x3fe700a7c5784633 */
266 7.21038110854851588272e-01, /* 0x3fe712be84295198 */
267 7.23237684576317874097e-01, /* 0x3fe724c35b4fae7b */
268 7.25428749044510712274e-01, /* 0x3fe736b65a172dff */
269 7.27611332626510676214e-01, /* 0x3fe748978fba8e0f */
270 7.29785463793429123314e-01, /* 0x3fe75a670b82d8d8 */
271 7.31951171115916565668e-01, /* 0x3fe76c24dcc6c6c0 */
272 7.34108483259739652560e-01, /* 0x3fe77dd112ea22c7 */
273 7.36257428981428097003e-01, /* 0x3fe78f6bbd5d315e */
274 7.38398037123989547936e-01, /* 0x3fe7a0f4eb9c19a2 */
275 7.40530336612692630105e-01, /* 0x3fe7b26cad2e50fd */
276 7.42654356450917929600e-01, /* 0x3fe7c3d311a6092b */
277 7.44770125716075148681e-01, /* 0x3fe7d528289fa093 */
278 7.46877673555587429099e-01, /* 0x3fe7e66c01c114fd */
279 7.48977029182941400620e-01, /* 0x3fe7f79eacb97898 */
280 7.51068221873802288613e-01, /* 0x3fe808c03940694a */
281 7.53151280962194302759e-01, /* 0x3fe819d0b7158a4c */
282 7.55226235836744863583e-01, /* 0x3fe82ad036000005 */
283 7.57293115936992444759e-01, /* 0x3fe83bbec5cdee22 */
284 7.59351950749757920178e-01, /* 0x3fe84c9c7653f7ea */
285 7.61402769805578416573e-01, /* 0x3fe85d69576cc2c5 */
286 7.63445602675201784315e-01, /* 0x3fe86e2578f87ae5 */
287 7.65480478966144461950e-01, /* 0x3fe87ed0eadc5a2a */
288 7.67507428319308182552e-01, /* 0x3fe88f6bbd023118 */
289 7.69526480405658186434e-01, /* 0x3fe89ff5ff57f1f7 */
290 7.71537664922959498526e-01, /* 0x3fe8b06fc1cf3dfe */
291 7.73541011592573490852e-01, /* 0x3fe8c0d9145cf49d */
292 7.75536550156311621507e-01, /* 0x3fe8d13206f8c4ca */
293 7.77524310373347682379e-01, /* 0x3fe8e17aa99cc05d */
294 7.79504322017186335181e-01, /* 0x3fe8f1b30c44f167 */
295 7.81476614872688268854e-01, /* 0x3fe901db3eeef187 */
296 7.83441218733151756304e-01, /* 0x3fe911f35199833b */
297 7.85398163397448278999e-01}; /* 0x3fe921fb54442d18 */
298
299 /* Some constants. */
300
301 static double pi = 3.1415926535897932e+00, /* 0x400921fb54442d18 */
302 piby2 = 1.5707963267948966e+00, /* 0x3ff921fb54442d18 */
303 piby4 = 7.8539816339744831e-01, /* 0x3fe921fb54442d18 */
304 three_piby4 = 2.3561944901923449e+00; /* 0x4002d97c7f3321d2 */
305
306 double u, v, vbyu, q, s, uu, r;
307 unsigned int swap_vu, index, xzero, yzero, xnan, ynan, xinf, yinf;
308 int xexp, yexp, diffexp;
309
310 double x = fx;
311 double y = fy;
312
313 /* Find properties of arguments x and y. */
314
315 unsigned long long ux, aux, xneg, uy, auy, yneg;
316
317 GET_BITS_DP64(x, ux);
318 GET_BITS_DP64(y, uy);
319 aux = ux & ~SIGNBIT_DP64;
320 auy = uy & ~SIGNBIT_DP64;
321 xexp = (int)((ux & EXPBITS_DP64) >> EXPSHIFTBITS_DP64);
322 yexp = (int)((uy & EXPBITS_DP64) >> EXPSHIFTBITS_DP64);
323 xneg = ux & SIGNBIT_DP64;
324 yneg = uy & SIGNBIT_DP64;
325 xzero = (aux == 0);
326 yzero = (auy == 0);
327 xnan = (aux > PINFBITPATT_DP64);
328 ynan = (auy > PINFBITPATT_DP64);
329 xinf = (aux == PINFBITPATT_DP64);
330 yinf = (auy == PINFBITPATT_DP64);
331
332 diffexp = yexp - xexp;
333
334 /* Special cases */
335
336 if (xnan)
337 {
338 unsigned int ufx;
339 GET_BITS_SP32(fx, ufx);
340 return _handle_errorf("atan2f", OP_ATAN2, ufx|0x00400000, _DOMAIN, 0,
341 EDOM, fx, fy, 2);
342 }
343 else if (ynan)
344 {
345 unsigned int ufy;
346 GET_BITS_SP32(fy, ufy);
347 return _handle_errorf("atan2f", OP_ATAN2, ufy|0x00400000, _DOMAIN, 0,
348 EDOM, fx, fy, 2);
349 }
350 else if (yzero)
351 { /* Zero y gives +-0 for positive x
352 and +-pi for negative x */
353 if (xneg)
354 {
355 if (yneg) return valf_with_flags((float)-pi, AMD_F_INEXACT);
356 else return valf_with_flags((float)pi, AMD_F_INEXACT);
357 }
358 else return (float)y;
359 }
360 else if (xzero)
361 { /* Zero x gives +- pi/2
362 depending on sign of y */
363 if (yneg) return valf_with_flags((float)-piby2, AMD_F_INEXACT);
364 else valf_with_flags((float)piby2, AMD_F_INEXACT);
365 }
366
367 if (diffexp > 26)
368 { /* abs(y)/abs(x) > 2^26 => arctan(x/y)
369 is insignificant compared to piby2 */
370 if (yneg) return valf_with_flags((float)-piby2, AMD_F_INEXACT);
371 else return valf_with_flags((float)piby2, AMD_F_INEXACT);
372 }
373 else if (diffexp < -13 && (!xneg))
374 { /* x positive and dominant over y by a factor of 2^13.
375 In this case atan(y/x) is y/x to machine accuracy. */
376
377 if (diffexp < -150) /* Result underflows */
378 {
379 if (yneg)
380 return valf_with_flags(-0.0F, AMD_F_INEXACT | AMD_F_UNDERFLOW);
381 else
382 return valf_with_flags(0.0F, AMD_F_INEXACT | AMD_F_UNDERFLOW);
383 }
384 else
385 {
386 if (diffexp < -126)
387 {
388 /* Result will likely be denormalized */
389 y = scaleDouble_1(y, 100);
390 y /= x;
391 /* Now y is 2^100 times the true result. Scale it back down. */
392 GET_BITS_DP64(y, uy);
393 scaleDownDouble(uy, 100, &uy);
394 PUT_BITS_DP64(uy, y);
395 if ((uy & EXPBITS_DP64) == 0)
396 return valf_with_flags((float)y, AMD_F_INEXACT | AMD_F_UNDERFLOW);
397 else
398 return (float)y;
399 }
400 else
401 return (float)(y / x);
402 }
403 }
404 else if (diffexp < -26 && xneg)
405 { /* abs(x)/abs(y) > 2^56 and x < 0 => arctan(y/x)
406 is insignificant compared to pi */
407 if (yneg) return valf_with_flags((float)-pi, AMD_F_INEXACT);
408 else return valf_with_flags((float)pi, AMD_F_INEXACT);
409 }
410 else if (yinf && xinf)
411 { /* If abs(x) and abs(y) are both infinity
412 return +-pi/4 or +- 3pi/4 according to
413 signs. */
414 if (xneg)
415 {
416 if (yneg) return valf_with_flags((float)-three_piby4, AMD_F_INEXACT);
417 else return valf_with_flags((float)three_piby4, AMD_F_INEXACT);
418 }
419 else
420 {
421 if (yneg) return valf_with_flags((float)-piby4, AMD_F_INEXACT);
422 else return valf_with_flags((float)piby4, AMD_F_INEXACT);
423 }
424 }
425
426 /* General case: take absolute values of arguments */
427
428 u = x; v = y;
429 if (xneg) u = -x;
430 if (yneg) v = -y;
431
432 /* Swap u and v if necessary to obtain 0 < v < u. Compute v/u. */
433
434 swap_vu = (u < v);
435 if (swap_vu) { uu = u; u = v; v = uu; }
436 vbyu = v/u;
437
438 if (vbyu > 0.0625)
439 { /* General values of v/u. Use a look-up
440 table and series expansion. */
441
442 index = (int)(256*vbyu + 0.5);
443 r = (256*v-index*u)/(256*u+index*v);
444
445 /* Polynomial approximation to atan(vbyu) */
446
447 s = r*r;
448 q = atan_jby256[index-16] + r - r*s*0.33333333333224095522;
449 }
450 else if (vbyu < 1.e-4)
451 { /* v/u is small enough that atan(v/u) = v/u */
452 q = vbyu;
453 }
454 else /* vbyu <= 0.0625 */
455 {
456 /* Small values of v/u. Use a series expansion */
457
458 s = vbyu*vbyu;
459 q = vbyu -
460 vbyu*s*(0.33333333333333170500 -
461 s*(0.19999999999393223405 -
462 s*0.14285713561807169030));
463 }
464
465 /* Tidy-up according to which quadrant the arguments lie in */
466
467 if (swap_vu) {q = piby2 - q;}
468 if (xneg) {q = pi - q;}
469 if (yneg) q = - q;
470 return (float)q;
471}
float __cdecl _handle_errorf(char *fname, int opcode, unsigned long long value, int type, int flags, int error, float arg1, float arg2, int nargs)
Definition: _handle_error.c:56
_Check_return_ float __cdecl atan2f(_In_ float x, _In_ float y)
Definition: atan2f.c:11
#define index(s, c)
Definition: various.h:29
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define EDOM
Definition: errno.h:39
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
const GLdouble * v
Definition: gl.h:2040
GLdouble s
Definition: gl.h:2039
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLuint index
Definition: glext.h:6031
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
#define _DOMAIN
Definition: math.h:39
#define FN_PROTOTYPE(fname)
Definition: libm.h:29
#define AMD_F_INEXACT
Definition: libm_new.h:82
#define AMD_F_UNDERFLOW
Definition: libm_new.h:84
#define GET_BITS_SP32(x, ux)
Definition: libm_util.h:105
#define EXPSHIFTBITS_DP64
Definition: libm_util.h:56
#define GET_BITS_DP64(x, ux)
Definition: libm_util.h:118
#define PINFBITPATT_DP64
Definition: libm_util.h:53
#define SIGNBIT_DP64
Definition: libm_util.h:44
#define EXPBITS_DP64
Definition: libm_util.h:45
#define PUT_BITS_DP64(ux, x)
Definition: libm_util.h:124
static const WCHAR aux[]
static refpint_t pi[]
Definition: server.c:96
GLfixed fx
Definition: tritemp.h:484
GLfixed fy
Definition: tritemp.h:490