gl-1.1: Test that unused normal array in ff shader doesn't affect other arrays
[piglit.git] / generated_tests / gen_cl_math_builtins.py
blobc934f9ce3bc52ea1f781ed4e366e091fa662b20b
1 # coding=utf-8
2 # Copyright 2013 Advanced Micro Devices, Inc.
4 # Permission is hereby granted, free of charge, to any person obtaining a
5 # copy of this software and associated documentation files (the "Software"),
6 # to deal in the Software without restriction, including without limitation
7 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 # and/or sell copies of the Software, and to permit persons to whom the
9 # Software is furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice (including the next
12 # paragraph) shall be included in all copies or substantial portions of the
13 # Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 # SOFTWARE.
23 # Authors: Tom Stellard <thomas.stellard@amd.com>
24 # Aaron Watry <awatry@gmail.com>
27 import os
29 from genclbuiltins import gen, NEGNAN
30 from math import acos, acosh, asin, asinh, atan, atan2, atanh, cos, cosh, exp, expm1
31 from math import fabs, fmod, gamma, hypot, lgamma, log, log10, log1p, modf, pi, pow, sin, sinh, sqrt, tan, tanh
33 CLC_VERSION_MIN = {
34 'acos' : 10,
35 'acosh' : 10,
36 'acospi' : 10,
37 'asin' : 10,
38 'asinh' : 10,
39 'asinpi' : 10,
40 'atan' : 10,
41 'atan2' : 10,
42 'atan2pi' : 10,
43 'atanh' : 10,
44 'atanpi': 10,
45 'cbrt' : 10,
46 'ceil' : 10,
47 'copysign' : 10,
48 'cos' : 10,
49 'cosh' : 10,
50 'cospi' : 10,
51 'erf' : 10,
52 'erfc' : 10,
53 'exp' : 10,
54 'exp10' : 10,
55 'exp2' : 10,
56 'expm1' : 10,
57 'fabs' : 10,
58 'fdim' : 10,
59 'floor' : 10,
60 'fma' : 10,
61 'fmax' : 10,
62 'fmin' : 10,
63 'fmod' : 10,
64 'fract' : 10,
65 'frexp' : 10,
66 'hypot' : 10,
67 'ilogb' : 10,
68 'ldexp' : 10,
69 'lgamma' : 10,
70 'lgamma_r' : 10,
71 'log' : 10,
72 'log10' : 10,
73 'log1p' : 10,
74 'log2' : 10,
75 'logb' : 10,
76 'nan' : 10,
77 'mad' : 10,
78 'maxmag' : 11,
79 'minmag' : 11,
80 'modf' : 10,
81 'nextafter' : 10,
82 'pow' : 10,
83 'pown' : 10,
84 'powr' : 10,
85 'remainder' : 10,
86 'remquo' : 10,
87 'rint' : 10,
88 'rootn' : 10,
89 'round' : 10,
90 'rsqrt' : 10,
91 'sin' : 10,
92 'sincos' : 10,
93 'sinh' : 10,
94 'sinpi' : 10,
95 'sqrt' : 10,
96 'tan' : 10,
97 'tanh' : 10,
98 'tanpi' : 10,
99 'tgamma' : 10,
100 'trunc' : 10
103 DATA_TYPES = ['float']
105 F = {
106 'float' : 'float'
109 I = {
110 'float' : 'int'
113 U = {
114 'float' : 'uint'
117 M_PI_F = float.fromhex('0x1.921fb6p+1')
119 def quo(x, y):
120 return int(round(x/y))
122 tests = {
123 'acos' : {
124 'arg_types' : [F, F],
125 'function_type': 'ttt',
126 'values' : [
127 [ pi, pi/2, 0.0, acos(0.12345), float("nan")], # Result
128 [-1.0, 0.0, 1.0, 0.12345, float("nan")] # Arg0
130 'tolerance' : 4
132 'acosh' : {
133 'arg_types' : [F, F],
134 'function_type': 'ttt',
135 'values' : [
136 [0.0, acosh(1.12345), float("nan"), acosh(123456789.01234)], #Result
137 [1.0, 1.12345, float("nan"), 123456789.01234 ] #Arg0
139 'tolerance' : 4
141 'acospi' : {
142 'arg_types' : [F, F],
143 'function_type': 'ttt',
144 'values' : [
145 [ 1, 1/2, 0.0, acos(0.12345) / pi, float("nan")], # Result
146 [-1.0, 0.0, 1.0, 0.12345, float("nan")] # Arg0
148 'tolerance' : 5
150 'asin' : {
151 'arg_types' : [F, F],
152 'function_type': 'ttt',
153 'values' : [
154 [-pi/2, 0.0, pi/2, asin(0.12345), float("nan")], # Result
155 [-1.0, 0.0, 1.0, 0.12345, float("nan")] # Arg0
157 'tolerance' : 4
159 'asinh' : {
160 'arg_types' : [F, F],
161 'function_type': 'ttt',
162 'values' : [
163 [0.0, asinh(1.0), asinh(-1.12345), float("nan"), asinh(123456789.01234)], #Result
164 [0.0, 1.0, -1.12345, float("nan"), 123456789.01234 ] #Arg0
166 'tolerance' : 4
168 'asinpi' : {
169 'arg_types' : [F, F],
170 'function_type': 'ttt',
171 'values' : [
172 [-1/2, 0.0, 1/2, asin(0.12345)/pi, float("nan")], # Result
173 [-1.0, 0.0, 1.0, 0.12345, float("nan")] # Arg0
175 'tolerance' : 5
177 'atan' : {
178 'arg_types' : [F, F],
179 'function_type': 'ttt',
180 'values' : [
181 [atan(0.0), atan(0.12345), atan(3567147.0)], # Result
182 [0.0, 0.12345, 3567147.0]# Arg0
184 'tolerance' : 5
186 'atan2' : {
187 'arg_types' : [F, F, F],
188 'function_type': 'ttt',
189 'values' : [
190 [atan2(0.0, 0.0), atan2(1.2345, 10.0), atan2(35671470.0, 0.1)], # Result
191 [0.0, 1.2345, 35671470.0 ], # Arg0
192 [0.0, 10.0, 0.1 ] # Arg1
194 'tolerance' : 6
196 'atan2pi' : {
197 'arg_types' : [F, F, F],
198 'function_type': 'ttt',
199 'values' : [
200 [atan2(0.0, 0.0)/pi, atan2(1.2345, 10.0)/pi, atan2(35671470.0, 0.1)/pi], # Result
201 [0.0, 1.2345, 35671470.0 ], # Arg0
202 [0.0, 10.0, 0.1 ] # Arg1
204 'tolerance' : 6
206 'atanh' : {
207 'arg_types' : [F, F],
208 'function_type': 'ttt',
209 'values' : [
210 [0.0, float("inf"), float("-inf"), float("nan"), atanh(0.123456789)], #Result
211 [0.0, 1.0, -1.0, float("nan"), 0.123456789 ] #Arg0
213 'tolerance' : 5
215 'atanpi' : {
216 'arg_types' : [F, F],
217 'function_type': 'ttt',
218 'values' : [
219 [0.0, -0.0, atan(1.02345)/pi, atan(-1.02345)/pi, float("nan"), 0.5, -0.5 ],
220 [0.0, -0.0, 1.02345, -1.02345, float("nan"), float("inf"), float("-inf") ]
222 'tolerance' : 5
224 'cbrt' : {
225 'arg_types': [F, F],
226 'function_type': 'ttt',
227 'values': [
228 [3.0, -1.0, float("nan"), float("inf"), 0.123456789**(1/3.0) ],
229 [27.0, -1.0, float("nan"), float("inf"), 0.123456789 ]
231 'tolerance' : 2
233 'ceil' : {
234 'arg_types': [F, F],
235 'function_type': 'ttt',
236 'values': [
237 [1.0, 0.0, 0.0, -0.0, float("nan"), -3.0],
238 [0.5, -0.5, 0.0, -0.0, float("nan"), -3.99]
241 'copysign' : {
242 'arg_types': [F, F, F],
243 'function_type': 'ttt',
244 'values': [
245 [0.0, -0.0, 1.0, -1.0, float("nan"), float("nan"), NEGNAN, float("-inf"), float("inf") ], # Result
246 [0.0, 0.0, 1.0, -1.0, float("nan"), -4.0, float("nan"), float("inf"), float("-inf") ], # Arg0
247 [1.0, -1.0, 2.0, -2.0, float("nan"), float("nan"), -4.0, -3.0, float("inf") ], # Arg1
250 'cos' : {
251 'arg_types' : [F, F],
252 'function_type': 'ttt',
253 'values' : [
254 # using libm cosf(3.0f * M_PI / 2.0f) == 0x1.99bc5cp-27
255 # this is different form what python gives us
256 [1.0, cos(M_PI_F / 2), -1.0, float.fromhex('0x1.99bc5cp-27'), 1.0, cos(1.12345), cos(7), cos(8), cos(pow(2,20)), cos(pow(2,24)), cos(pow(2,120)), float("nan")], # Result
257 [0.0, M_PI_F / 2, pi, 3 * M_PI_F / 2, 2 * pi, 1.12345, 7, 8, pow(2,20), pow(2,24), pow(2,120), float("nan")] # Arg0
259 'tolerance' : 4
261 'cosh' : {
262 'arg_types' : [F, F],
263 'function_type': 'ttt',
264 'values' : [
265 [1.0, cosh(0.123456789), float("inf"), float("inf"), float("nan")],# Result
266 [0.0, 0.123456789, float("inf"), float("-inf"), float("nan")] # Arg0
268 'tolerance' : 4
270 'cospi' : {
271 'arg_types' : [F, F],
272 'function_type': 'ttt',
273 'values' : [
274 [1.0, cos(pi * M_PI_F / 2), cos(pi*3*pi/2), cos(2 * M_PI_F * pi), cos(pi*1.12345), cos(pi*pow(2,20)), cos(pi*pow(2,24)), 1.0, float("nan")], # Result
275 [0.0, pi / 2, 3 * pi / 2, 2 * pi, 1.12345 , pow(2,20), pow(2,24), pow(2,120), float("nan")] # Arg0
277 'tolerance' : 4
279 'erf' : {
280 'arg_types' : [F, F],
281 'function_type': 'ttt',
282 'values' : [
283 [0.0, 0.950004, 0.990005, -0.994999475, 1.0, 1, -1], # Result
284 [0.0, 1.960/sqrt(2.0), 2.576/sqrt(2.0), -2.807/sqrt(2.0), 11.1, float("inf"), float("-inf")] # Arg0
286 'tolerance' : 16
288 'erfc' : {
289 'arg_types' : [F, F],
290 'function_type': 'ttt',
291 'values' : [
292 [1.0, float.fromhex('0x1.9990c6p-5'), float.fromhex('0x1.4784aep-7'), 1.994999, 0.0, 0.0, 2.0], # Result
293 [0.0, 1.960/sqrt(2.0), 2.576/sqrt(2.0), -2.807/sqrt(2.0), 11.1, float("inf"), float("-inf")] # Arg0
295 'tolerance' : 16
297 'exp' : {
298 'arg_types' : [F, F],
299 'function_type': 'ttt',
300 'values' : [
301 [1.0, exp(0.95), exp(pi), exp(-pi), float("inf"), float.fromhex('0x1.66fe8ap+4')], # Result
302 [0.0, 0.95, pi, -pi, float("inf"), float.fromhex('0x1.8e2cp+1')] # Arg0
304 'tolerance' : 3
306 'exp10' : {
307 'arg_types' : [F, F],
308 'function_type': 'ttt',
309 'values' : [
310 [1.0, 10 ** 0.95, 10 ** pi, 10 ** -pi, float("inf"), float.fromhex('0x1.4298593c335e3p+10')], # Result
311 [0.0, 0.95, pi, -pi, float("inf"), float.fromhex('0x1.8e2cp+1')] # Arg0
313 'tolerance' : 3
315 'exp2' : {
316 'arg_types' : [F, F],
317 'function_type': 'ttt',
318 'values' : [
319 [1.0, 2 ** 0.95, 2 ** pi, 2 ** -pi, float("inf"), float.fromhex('0x1.146b7fd8431e3p+3')], # Result
320 [0.0, 0.95, pi, -pi, float("inf"), float.fromhex('0x1.8e2cp+1')] # Arg0
322 'tolerance' : 3
324 'expm1' : {
325 'arg_types' : [F, F],
326 'function_type': 'ttt',
327 'values' : [
328 [0.0, expm1(0.95), expm1(pi), expm1(-pi), float("inf"), float.fromhex('0x1.56fe8a160893ep+4')], # Result
329 [0.0, 0.95, pi, -pi, float("inf"), float.fromhex('0x1.8e2cp+1')] # Arg0
331 'tolerance' : 3
333 'fabs' : {
334 'arg_types' : [F, F],
335 'function_type': 'ttt',
336 'values' : [
337 [0.0, pi/2, pi, 0.0, float("inf"), float("inf"), 1.12345 ], # Result
338 [0.0, -pi/2, pi, -0.0, float("-inf"), float("inf"), -1.12345] # Arg0
340 'tolerance' : 0
342 'fdim' : {
343 'arg_types' : [F, F, F],
344 'function_type': 'ttt',
345 'values' : [
346 [0.0, 0.75, 0.0, 0.0, float("inf"), 0.0, float("nan"), float("nan"), float("nan"), 2.2469 ], # Result
347 [0.3, 1.0, pi, 0.0, float("inf"), float("inf"), float("nan"), 1.0, float("nan"), 1.12345 ], # Arg0
348 [1.5, 0.25, pi, -0.0, float("-inf"), float("inf"), float("nan"), float("nan"), 1.0, -1.12345] # Arg1
351 'floor' : {
352 'arg_types': [F, F],
353 'function_type': 'ttt',
354 'values': [
355 [0.0, -1.0, 0.0, -0.0, float("nan"), -4.0, 1.0],
356 [0.5, -0.5, 0.0, -0.0, float("nan"), -3.99, 1.5]
359 'fma' : {
360 'arg_types': [F, F, F, F],
361 'function_type': 'tss',
362 'values': [
363 [pi, 1.0, pi , -0.5, float("nan"), float("nan"), float("nan")], # Result
364 [1.0, pi, 0.0, 0.0, 1.0, float("nan"), float("nan")], # Arg0
365 [pi, 0.0, pi, -0.5, float("nan"), 1.0, float("nan")], # Arg1
366 [0.0, 1.0, pi, -0.5, float("nan"), 1.0, float("nan")] # Arg2
369 'fmax' : {
370 'arg_types': [F, F, F],
371 'function_type': 'tss',
372 'values': [
373 [1.0, 0.0, 0.0, 0.0, 1.0, 1.0, float("nan")], #Result
374 [1.0, -0.5, 0.0, 0.0, 1.0, float("nan"), float("nan")], #Arg0
375 [0.0, 0.0, 0.0, -0.5, float("nan"), 1.0, float("nan")] #Arg1
378 'fmin' : {
379 'arg_types': [F, F, F],
380 'function_type': 'tss',
381 'values': [
382 [0.0, -0.5, 0.0, -0.5, 1.0, 1.0, float("nan")], #Result
383 [1.0, -0.5, 0.0, 0.0, 1.0, float("nan"), float("nan")], #Arg0
384 [0.0, 0.0, 0.0, -0.5, float("nan"), 1.0, float("nan")] #Arg1
387 'fmod' : {
388 'arg_types': [F, F, F],
389 'function_type': 'ttt',
390 'values': [
391 [float.fromhex("0x1.99998p-4"), float("nan"), float.fromhex("-0x1.47aep-7"), 1.0, float("-nan"), float("nan")],
392 [float.fromhex("0x1.466666p+2"), 0.0, float.fromhex("-0x1p+2"), 1.0, 5.1, 3.0 ],
393 [float.fromhex("0x1p-1"), float("nan"), float.fromhex("-0x1.feb852p+1"), 1.5, 0.0, float("inf")]
395 'tolerance' : 0
397 'fract' : {
398 'arg_types': [F, F, F],
399 'function_type': 'ttt',
400 # For fract we have two outputs per address space.
401 'values': [
402 [float("nan"), 0.0, 0.5, 0.0, float.fromhex('0x1.33333p-2'), float.fromhex('0x1.fffffep-1') ], #fract
403 [float("nan"), float("inf"), 1.0, 2.0, -2.0, -1.0], #floor
404 [float("nan"), float("inf"), 1.5, 2.0,float.fromhex('-0x1.b33334p+0'), float.fromhex('-0x1.000242p-24')] #src0
406 'num_out_args' : 2
408 'frexp' : {
409 'arg_types': [F, I, F],
410 'function_type': 'ttt',
411 # For frexp we have two outputs per address space.
412 'values': [
413 [0.602783203125, 0.5, float("nan"), float("nan"), float("inf"), float("-inf"), 0.0],
414 [11, 1, 0, 0, 0, 0, 0],
415 [1234.5, 1.0, float("nan"), float("-nan"), float("inf"), float("-inf"), 0.0]
417 'num_out_args' : 2
419 'hypot' : {
420 'arg_types': [F, F, F],
421 'function_type': 'ttt',
422 'values': [
423 [hypot(0, 1.0), hypot(3, 10.0), hypot(1, -3.0), hypot(10, 1234.5), hypot(2147483647, -1.0), float("inf")], # Result
424 [0, 3, 1, 10, 2147483647, 2147483647], # Arg0
425 [1.0, 10.0, -3.0, 1234.5, -1.0, float("-inf")] # Arg1
427 'tolerance' : 4
429 'ilogb' : {
430 'arg_types': [I, F],
431 'function_type': 'ttt',
432 'values': [
433 [0, 3, 1, 10, 2147483647, 2147483647],
434 [1.0, 10.0, -3.0, 1234.5, float("inf"), float("-inf")]
436 'tolerance' : 0
438 'ldexp' : {
439 'arg_types': [F, F, I],
440 'function_type': 'tss',
441 'values': [
442 [0.0, 4.0, 15.2, 1.75, float("nan"), float("inf")],
443 [0.0, 1.0, 0.95, 3.5, float("nan"), 1.12312312],
444 [0, 2, 4, -1, 1, 2031231231]
446 'tolerance' : 0
448 'lgamma' : {
449 'arg_types': [F, F],
450 'function_type': 'ttt',
451 'values': [
452 [0.0, lgamma(1.5), lgamma(0.5), float("nan"), lgamma(1.e-15), float("nan")], # Result
453 [1.0, 1.5, 0.5, 0.0, 1.e-15, float("nan")] # Arg
455 'tolerance' : 16777216 # Specs say it's currently undefined
457 'lgamma_r' : {
458 'arg_types': [F, I, F],
459 'function_type': 'ttt',
460 'values': [
461 [0.0, lgamma(1.5), lgamma(0.5), float("nan"), lgamma(1.e-15), float("nan")], # Result0
462 [1, -1, 1, 1, 1, 1], # Result1
463 [1.0, 1.5, 0.5, 0.0, 1.e-15, float("nan")] # Arg
465 'tolerance' : 16777216, # Specs say it's currently undefined
466 'num_out_args' : 2
468 'log' : {
469 'arg_types': [F, F],
470 'function_type': 'ttt',
471 'values': [
472 [log(0.5), float("-inf"), log(1.e-15), float("nan")], #Result
473 [0.5, 0.0, 1.e-15, float("nan")] #Arg0
475 'tolerance' : 3
477 'log10' : {
478 'arg_types': [F, F],
479 'function_type': 'ttt',
480 'values': [
481 [log10(0.5), float("-inf"), log10(1.e-15), float("nan")],
482 [0.5, 0.0, 1.e-15, float("nan")]
484 'tolerance' : 3
486 'log1p' : {
487 'arg_types': [F, F],
488 'function_type': 'ttt',
489 'values': [
490 [log1p(0.5), float("-inf"), log1p(1.e-15), float("nan")],
491 [0.5, -1.0, 1.e-15, float("nan")]
493 'tolerance' : 2
495 'log2' : {
496 'arg_types': [F, F],
497 'function_type': 'ttt',
498 'values': [
499 [log(0.5, 2), float("-inf"), log(1.e-15, 2), float("nan")], #Result
500 [0.5, 0.0, 1.e-15, float("nan")] #Arg0
502 'tolerance' : 3
504 'logb' : {
505 'arg_types': [F, F],
506 'function_type': 'ttt',
507 'values': [
508 [0, 3, 1, 10, float("inf"), float("inf")], #Result
509 [1.0, 10.0, -3.0, 1234.5, float("inf"), float("-inf")] #Arg0
511 'tolerance' : 0
513 'mad' : {
514 'arg_types': [F, F, F, F],
515 'function_type': 'tss',
516 'values': [
517 [pi, 1.0, pi , -0.5, float("nan"), float("nan"), float("nan")], # Result
518 [1.0, pi, 0.0, 0.0, 1.0, float("nan"), float("nan")], # Arg0
519 [pi, 0.0, pi, -0.5, float("nan"), 1.0, float("nan")], # Arg1
520 [0.0, 1.0, pi, -0.5, float("nan"), 1.0, float("nan")] # Arg2
522 'tolerance' : 16777216 #infinite ULP
524 'maxmag' : {
525 'arg_types': [F, F, F],
526 'function_type': 'ttt',
527 'values': [
528 [1.0, -0.5, 0.0, -0.5, 1.0, 1.0, float("nan")], #Result
529 [1.0, -0.5, 0.0, 0.0, 1.0, float("nan"), float("nan")], #Arg0
530 [0.0, 0.0, 0.0, -0.5, float("nan"), 1.0, float("nan")] #Arg1
533 'minmag' : {
534 'arg_types': [F, F, F],
535 'function_type': 'ttt',
536 'values': [
537 [0.0, -0.5, 0.0, 1.0, 1.0, 1.0, float("nan")], #Result
538 [1.0, -0.5, 1.0, 1.0, 1.0, float("nan"), float("nan")], #Arg0
539 [0.0, 1.0, 0.0, -1.5, float("nan"), 1.0, float("nan")] #Arg1
542 'modf' : {
543 'arg_types': [F, F, F],
544 'function_type': 'ttt',
545 'values': [
546 [0.0, modf(1.5)[0], modf(0.25)[0], 0.0, modf(1.e-15)[0], float("nan")], # Result0
547 [1, modf(1.5)[1], modf(0.25)[1], 0.0, modf(1.e-15)[1], float("nan")], # Result1
548 [1.0, 1.5, 0.25, 0.0, 1.e-15, float("nan")] # Arg
550 'num_out_args' : 2
552 # FIXME: kernel names are broken, and we cant really compare nans to see if the
553 # code made it
554 # 'nan' : {
555 # 'arg_types': [F, U],
556 # 'function_type': 'ttt',
557 # 'values': [
558 # [float("nan"), float("nan"), float("nan")],
559 # [0xdead, 0xadbeef, 0xdead]
560 # ],
561 # 'tolerance' : 0
562 # },
563 'nextafter' : {
564 'arg_types': [F, F, F],
565 'function_type': 'ttt',
566 'values': [
567 [1.401298e-45, -1.401298e-45, 1.00000011920928955078125, 0.999999940395355224609375, float("nan"), float("nan"), 5.0 ], # Result
568 [0.0, 0.0 , 1.0, 1.0, float("nan"), 2.5, 5.0], # Arg0
569 [1.0, -1.0 , 2.0, 0.0, 3.4, float("nan"), 5.0], # Arg1
572 'pow' : {
573 'arg_types': [F, F, F],
574 'function_type': 'ttt',
575 'values': [
576 [pow(0, 1.0), pow(-3, 10.0), pow(-11, -3.0), pow(1234.5, 10), pow(2147483647, -1.0), float("inf")], # Result
577 [0, -3, -11, 1234.5, 2147483647, 2147483647], # Arg0
578 [1.0, 10.0, -3.0, 10, -1.0, float("-inf")] # Arg1
580 'tolerance' : 16
582 'pown' : {
583 'arg_types': [F, F, I],
584 'function_type': 'ttt',
585 'values': [
586 [pow(1, 0), pow(10.0, 3), pow(-3.3, -4), pow(1234, 10), pow(-1, 2147483647), float("-inf")], # Result
587 [1.0, 10.0, -3.3, 1234, -1.0, float("-inf")], # Arg0
588 [0, 3, -4, 10, 2147483647, 2147483647] # Arg1
590 'tolerance' : 16
592 'powr' : {
593 'arg_types': [F, F, F],
594 'function_type': 'ttt',
595 'values': [
596 [pow(0, 1.0), pow(3, 10.0), pow(11, -3.0), pow(1234.5, 10), pow(2147483647, -1.0), 0.0], # Result
597 [0, 3, 11, 1234.5, 2147483647, 2147483647], # Arg0
598 [1.0, 10.0, -3.0, 10, -1.0, float("-inf")] # Arg1
600 'tolerance' : 16
602 'remainder' : {
603 'arg_types': [F, F, F],
604 'function_type': 'ttt',
605 'values': [
606 [float.fromhex("-0x1.ccccdp-1"), float.fromhex("0x1.ccccdp-1"),
607 float.fromhex("-0x1.ccccdp-1"), float.fromhex("0x1.ccccdp-1"),
608 0.0, -0.0, 5.1, float("-nan")
609 ], # Result
610 [ 5.1, -5.1, 5.1, -5.1, 0.0, -0.0, 5.1, 5.1], # Arg0
611 [ 3.0, 3.0, -3.0, -3.0, 1.0, 1.0, float("inf"), 0.0], # Arg1
614 'remquo' : {
615 'arg_types': [F, I, F, F],
616 'function_type': 'ttt',
617 'values': [
618 [float.fromhex("-0x1.ccccdp-1"), float.fromhex("0x1.ccccdp-1"),
619 float.fromhex("-0x1.ccccdp-1"), float.fromhex("0x1.ccccdp-1"),
620 0.0, -0.0, 5.1, float("-nan")
621 ], # Result
622 [quo(5.1, 3.0), quo(-5.1, 3.0), quo(5.1, -3.0), quo(-5.1, -3.0),
623 quo(0.0, 1.0), quo(-0.0, 1.0), quo(5.1, float("inf")), 0], # Arg0
624 [ 5.1, -5.1, 5.1, -5.1, 0.0, -0.0, 5.1, 5.1], # Arg0
625 [ 3.0, 3.0, -3.0, -3.0, 1.0, 1.0, float("inf"), 0.0], # Arg1
627 'num_out_args' : 2
629 'rint' : {
630 'arg_types': [F, F],
631 'function_type': 'ttt',
632 'values': [
633 [0.0, -0.0, 1.0, -1.0, float("nan"), -4.0, 2.0, 0.0, 1.0],
634 [0.5, -0.5, 0.6, -0.6, float("nan"), -3.99, 1.5, 0.4, 0.6]
637 'rootn' : {
638 'arg_types': [F, F, I],
639 'function_type': 'ttt',
640 'values': [
641 [pow(1, 1/2), pow(10.0, 1/3), float("nan"), pow(1234, 1/10), -1, float("-inf")], # Result
642 [1.0, 10.0, -3.3, 1234, -1.0, float("-inf")], # Arg0
643 [2, 3, -4, 10, 2147483647, 2147483647] # Arg1
645 'tolerance' : 16
647 'round' : {
648 'arg_types': [F, F],
649 'function_type': 'ttt',
650 'values': [
651 [1.0, -1.0, 0.0, -0.0, float("nan"), -4.0, 2.0, 0.0, 1.0],
652 [0.5, -0.5, 0.0, -0.0, float("nan"), -3.99, 1.5, 0.4, 0.6]
655 'rsqrt' : {
656 'arg_types': [F, F],
657 'function_type': 'ttt',
658 'values': [
659 [1.0, 1.0/2.0, 1/6.0, 1/2.5 , float("nan"), 1/4.0, float("inf"), 1/sqrt(7.0), 1/sqrt(pi)], # Result
660 [1.0, 4.0, 36.0, 6.25, float("nan"), 16.0, 0.0, 7.0, pi], # Arg1
662 'tolerance': 2
664 'sin' : {
665 'arg_types' : [F, F],
666 'function_type': 'ttt',
667 'values' : [
668 [0.0, 1.0, sin(M_PI_F), -1.0, sin(2 * M_PI_F), sin(2.234567), sin(7), sin(8), sin(pow(2,20)), sin(pow(2,24)), sin(pow(2,120)), float("nan")], # Result
669 [0.0, pi / 2, pi, 3 * pi / 2, 2 * pi, 2.234567, 7, 8, pow(2,20), pow(2,24), pow(2,120), float("nan")] # Arg0
671 'tolerance': 4
673 'sincos' : {
674 'arg_types' : [F, F, F],
675 'function_type': 'ttt',
676 'values' : [
677 [0.0, 1.0, sin(M_PI_F), -1.0, sin(2 * M_PI_F), sin(2.234567), sin(7), sin(8), sin(pow(2,20)), sin(pow(2,24)), sin(pow(2,120)), float("nan")], # Result0
678 # using libm cosf(3.0f * M_PI / 2.0f) == 0x1.99bc5cp-27
679 # this is different form what python gives us
680 [1.0, cos(M_PI_F / 2), -1.0, float.fromhex('0x1.99bc5cp-27'), 1.0, cos(2.234567), cos(7), cos(8), cos(pow(2,20)), cos(pow(2,24)), cos(pow(2,120)), float("nan")], # Result1
681 [0.0, pi / 2, pi, 3 * pi / 2, 2 * pi, 2.234567, 7, 8, pow(2,20), pow(2,24), pow(2,120), float("nan")] # Arg0
683 'tolerance': 4,
684 'num_out_args' : 2
686 'sinh' : {
687 'arg_types' : [F, F],
688 'function_type': 'ttt',
689 'values' : [
690 [0.0, sinh(0.123456789), float("inf"), float("-inf"), float("nan")],# Result
691 [0.0, 0.123456789, float("inf"), float("-inf"), float("nan")] # Arg0
693 'tolerance': 4
695 'sinpi' : {
696 'arg_types' : [F, F],
697 'function_type': 'ttt',
698 'values' : [
699 [0.0, 0.0, sin(pi*pi/2), sin(pi*3*pi/2), sin(2* M_PI_F * pi),
700 sin(pi*1.12345), 0.0, 0.0, 0.0, 0.0, 0.0, float("nan")],#Result
701 [0.0, 1.0, pi / 2, 3 * pi / 2, 2 * pi,
702 1.12345 , 7.0, 8.0, pow(2,20), pow(2,24), pow(2,120),
703 float("nan")] #Arg0
705 'tolerance' : 4
707 'sqrt' : {
708 'arg_types': [F, F],
709 'function_type': 'ttt',
710 'values': [
711 [1.0, 2.0, 6.0, 2.5 , float("nan"), 4.0, sqrt(0.0), sqrt(7.0), sqrt(pi)], # Result
712 [1.0, 4.0, 36.0, 6.25, float("nan"), 16.0, 0.0, 7.0, pi], # Arg1
714 'tolerance': 3
716 'tan' : {
717 'arg_types': [F, F],
718 'function_type': 'ttt',
719 'values': [
720 [0.0, 1.0, tan(M_PI_F), sqrt(3), -1.0, tan(2.234567), float("nan") ], # Result
721 [0.0, pi/4, M_PI_F, pi/3, 3*pi/4, 2.234567 , float("nan") ], # Arg1
723 'tolerance': 5
725 'tanh' : {
726 'arg_types' : [F, F],
727 'function_type': 'ttt',
728 'values' : [
729 [0.0, tanh(0.123456789), tanh(15.123456789), 1.0, -1.0 , float("nan")],# Result
730 [0.0, 0.123456789, 15.123456789, float("inf"), float("-inf"), float("nan")] # Arg0
732 'tolerance': 5
734 'tanpi' : {
735 'arg_types': [F, F],
736 'function_type': 'ttt',
737 'values': [
738 #fp32 representation of 2.234567 is 0x1.1e064ap+1
739 [0.0, 1.0, 0.0, sqrt(3), -1.0, tan(M_PI_F * float.fromhex('0x1.1e064ap+1')), float("nan") ], # Result
740 [0.0, 1/4, 1, 1/3, 3/4, 2.234567, float("nan") ], # Arg1
742 'tolerance': 6
744 'tgamma' : {
745 'arg_types': [F, F],
746 'function_type': 'ttt',
747 'values': [
748 [1.0, gamma(1.5), gamma(0.5), float("nan"), gamma(1.e-15), float("nan")], # Result
749 [1.0, 1.5, 0.5, 0.0, 1.e-15, float("nan")] # Arg
751 'tolerance' : 16
753 'trunc' : {
754 'arg_types': [F, F],
755 'function_type': 'ttt',
756 'values': [
757 [0.0, -0.0, 0.0, -0.0, float("nan"), -3.0, 1.0],
758 [0.5, -0.5, 0.0, -0.0, float("nan"), -3.99, 1.5]
764 def main():
765 dirName = os.path.join("cl", "builtin", "math")
767 testDefs = {}
768 functions = sorted(tests.keys())
769 for dataType in DATA_TYPES:
770 for fnName in functions:
771 testDefs[(dataType, fnName)] = tests[fnName]
773 gen(DATA_TYPES, CLC_VERSION_MIN, functions, testDefs, dirName)
776 if __name__ == '__main__':
777 main()