summary/html: escape html
[piglit.git] / generated_tests / gen_cl_math_builtins.py
blob566b2dcf367d7083b0ca68c25c48a3b11679ae15
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 from __future__ import print_function, division, absolute_import
28 import os
30 from genclbuiltins import gen, NEGNAN
31 from math import acos, acosh, asin, asinh, atan, atan2, atanh, cos, cosh, exp, expm1
32 from math import fabs, fmod, gamma, hypot, lgamma, log, log10, log1p, modf, pi, pow, sin, sinh, sqrt, tan, tanh
34 CLC_VERSION_MIN = {
35 'acos' : 10,
36 'acosh' : 10,
37 'acospi' : 10,
38 'asin' : 10,
39 'asinh' : 10,
40 'asinpi' : 10,
41 'atan' : 10,
42 'atan2' : 10,
43 'atan2pi' : 10,
44 'atanh' : 10,
45 'atanpi': 10,
46 'cbrt' : 10,
47 'ceil' : 10,
48 'copysign' : 10,
49 'cos' : 10,
50 'cosh' : 10,
51 'cospi' : 10,
52 'erf' : 10,
53 'erfc' : 10,
54 'exp' : 10,
55 'exp10' : 10,
56 'exp2' : 10,
57 'expm1' : 10,
58 'fabs' : 10,
59 'fdim' : 10,
60 'floor' : 10,
61 'fma' : 10,
62 'fmax' : 10,
63 'fmin' : 10,
64 'fmod' : 10,
65 'fract' : 10,
66 'frexp' : 10,
67 'hypot' : 10,
68 'ilogb' : 10,
69 'ldexp' : 10,
70 'lgamma' : 10,
71 'lgamma_r' : 10,
72 'log' : 10,
73 'log10' : 10,
74 'log1p' : 10,
75 'log2' : 10,
76 'logb' : 10,
77 'nan' : 10,
78 'mad' : 10,
79 'maxmag' : 11,
80 'minmag' : 11,
81 'modf' : 10,
82 'nextafter' : 10,
83 'pow' : 10,
84 'pown' : 10,
85 'powr' : 10,
86 'remainder' : 10,
87 'remquo' : 10,
88 'rint' : 10,
89 'rootn' : 10,
90 'round' : 10,
91 'rsqrt' : 10,
92 'sin' : 10,
93 'sincos' : 10,
94 'sinh' : 10,
95 'sinpi' : 10,
96 'sqrt' : 10,
97 'tan' : 10,
98 'tanh' : 10,
99 'tanpi' : 10,
100 'tgamma' : 10,
101 'trunc' : 10
104 DATA_TYPES = ['float']
106 F = {
107 'float' : 'float'
110 I = {
111 'float' : 'int'
114 U = {
115 'float' : 'uint'
118 M_PI_F = float.fromhex('0x1.921fb6p+1')
120 def quo(x, y):
121 return int(round(x/y))
123 tests = {
124 'acos' : {
125 'arg_types' : [F, F],
126 'function_type': 'ttt',
127 'values' : [
128 [ pi, pi/2, 0.0, acos(0.12345), float("nan")], # Result
129 [-1.0, 0.0, 1.0, 0.12345, float("nan")] # Arg0
131 'tolerance' : 4
133 'acosh' : {
134 'arg_types' : [F, F],
135 'function_type': 'ttt',
136 'values' : [
137 [0.0, acosh(1.12345), float("nan"), acosh(123456789.01234)], #Result
138 [1.0, 1.12345, float("nan"), 123456789.01234 ] #Arg0
140 'tolerance' : 4
142 'acospi' : {
143 'arg_types' : [F, F],
144 'function_type': 'ttt',
145 'values' : [
146 [ 1, 1/2, 0.0, acos(0.12345) / pi, float("nan")], # Result
147 [-1.0, 0.0, 1.0, 0.12345, float("nan")] # Arg0
149 'tolerance' : 5
151 'asin' : {
152 'arg_types' : [F, F],
153 'function_type': 'ttt',
154 'values' : [
155 [-pi/2, 0.0, pi/2, asin(0.12345), float("nan")], # Result
156 [-1.0, 0.0, 1.0, 0.12345, float("nan")] # Arg0
158 'tolerance' : 4
160 'asinh' : {
161 'arg_types' : [F, F],
162 'function_type': 'ttt',
163 'values' : [
164 [0.0, asinh(1.0), asinh(-1.12345), float("nan"), asinh(123456789.01234)], #Result
165 [0.0, 1.0, -1.12345, float("nan"), 123456789.01234 ] #Arg0
167 'tolerance' : 4
169 'asinpi' : {
170 'arg_types' : [F, F],
171 'function_type': 'ttt',
172 'values' : [
173 [-1/2, 0.0, 1/2, asin(0.12345)/pi, float("nan")], # Result
174 [-1.0, 0.0, 1.0, 0.12345, float("nan")] # Arg0
176 'tolerance' : 5
178 'atan' : {
179 'arg_types' : [F, F],
180 'function_type': 'ttt',
181 'values' : [
182 [atan(0.0), atan(0.12345), atan(3567147.0)], # Result
183 [0.0, 0.12345, 3567147.0]# Arg0
185 'tolerance' : 5
187 'atan2' : {
188 'arg_types' : [F, F, F],
189 'function_type': 'ttt',
190 'values' : [
191 [atan2(0.0, 0.0), atan2(1.2345, 10.0), atan2(35671470.0, 0.1)], # Result
192 [0.0, 1.2345, 35671470.0 ], # Arg0
193 [0.0, 10.0, 0.1 ] # Arg1
195 'tolerance' : 6
197 'atan2pi' : {
198 'arg_types' : [F, F, F],
199 'function_type': 'ttt',
200 'values' : [
201 [atan2(0.0, 0.0)/pi, atan2(1.2345, 10.0)/pi, atan2(35671470.0, 0.1)/pi], # Result
202 [0.0, 1.2345, 35671470.0 ], # Arg0
203 [0.0, 10.0, 0.1 ] # Arg1
205 'tolerance' : 6
207 'atanh' : {
208 'arg_types' : [F, F],
209 'function_type': 'ttt',
210 'values' : [
211 [0.0, float("inf"), float("-inf"), float("nan"), atanh(0.123456789)], #Result
212 [0.0, 1.0, -1.0, float("nan"), 0.123456789 ] #Arg0
214 'tolerance' : 5
216 'atanpi' : {
217 'arg_types' : [F, F],
218 'function_type': 'ttt',
219 'values' : [
220 [0.0, -0.0, atan(1.02345)/pi, atan(-1.02345)/pi, float("nan"), 0.5, -0.5 ],
221 [0.0, -0.0, 1.02345, -1.02345, float("nan"), float("inf"), float("-inf") ]
223 'tolerance' : 5
225 'cbrt' : {
226 'arg_types': [F, F],
227 'function_type': 'ttt',
228 'values': [
229 [3.0, -1.0, float("nan"), float("inf"), 0.123456789**(1/3.0) ],
230 [27.0, -1.0, float("nan"), float("inf"), 0.123456789 ]
232 'tolerance' : 2
234 'ceil' : {
235 'arg_types': [F, F],
236 'function_type': 'ttt',
237 'values': [
238 [1.0, 0.0, 0.0, -0.0, float("nan"), -3.0],
239 [0.5, -0.5, 0.0, -0.0, float("nan"), -3.99]
242 'copysign' : {
243 'arg_types': [F, F, F],
244 'function_type': 'ttt',
245 'values': [
246 [0.0, -0.0, 1.0, -1.0, float("nan"), float("nan"), NEGNAN, float("-inf"), float("inf") ], # Result
247 [0.0, 0.0, 1.0, -1.0, float("nan"), -4.0, float("nan"), float("inf"), float("-inf") ], # Arg0
248 [1.0, -1.0, 2.0, -2.0, float("nan"), float("nan"), -4.0, -3.0, float("inf") ], # Arg1
251 'cos' : {
252 'arg_types' : [F, F],
253 'function_type': 'ttt',
254 'values' : [
255 # using libm cosf(3.0f * M_PI / 2.0f) == 0x1.99bc5cp-27
256 # this is different form what python gives us
257 [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
258 [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
260 'tolerance' : 4
262 'cosh' : {
263 'arg_types' : [F, F],
264 'function_type': 'ttt',
265 'values' : [
266 [1.0, cosh(0.123456789), float("inf"), float("inf"), float("nan")],# Result
267 [0.0, 0.123456789, float("inf"), float("-inf"), float("nan")] # Arg0
269 'tolerance' : 4
271 'cospi' : {
272 'arg_types' : [F, F],
273 'function_type': 'ttt',
274 'values' : [
275 [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
276 [0.0, pi / 2, 3 * pi / 2, 2 * pi, 1.12345 , pow(2,20), pow(2,24), pow(2,120), float("nan")] # Arg0
278 'tolerance' : 4
280 'erf' : {
281 'arg_types' : [F, F],
282 'function_type': 'ttt',
283 'values' : [
284 [0.0, 0.950004, 0.990005, -0.994999475, 1.0, 1, -1], # Result
285 [0.0, 1.960/sqrt(2.0), 2.576/sqrt(2.0), -2.807/sqrt(2.0), 11.1, float("inf"), float("-inf")] # Arg0
287 'tolerance' : 16
289 'erfc' : {
290 'arg_types' : [F, F],
291 'function_type': 'ttt',
292 'values' : [
293 [1.0, float.fromhex('0x1.9990c6p-5'), float.fromhex('0x1.4784aep-7'), 1.994999, 0.0, 0.0, 2.0], # Result
294 [0.0, 1.960/sqrt(2.0), 2.576/sqrt(2.0), -2.807/sqrt(2.0), 11.1, float("inf"), float("-inf")] # Arg0
296 'tolerance' : 16
298 'exp' : {
299 'arg_types' : [F, F],
300 'function_type': 'ttt',
301 'values' : [
302 [1.0, exp(0.95), exp(pi), exp(-pi), float("inf"), float.fromhex('0x1.66fe8ap+4')], # Result
303 [0.0, 0.95, pi, -pi, float("inf"), float.fromhex('0x1.8e2cp+1')] # Arg0
305 'tolerance' : 3
307 'exp10' : {
308 'arg_types' : [F, F],
309 'function_type': 'ttt',
310 'values' : [
311 [1.0, 10 ** 0.95, 10 ** pi, 10 ** -pi, float("inf"), float.fromhex('0x1.4298593c335e3p+10')], # Result
312 [0.0, 0.95, pi, -pi, float("inf"), float.fromhex('0x1.8e2cp+1')] # Arg0
314 'tolerance' : 3
316 'exp2' : {
317 'arg_types' : [F, F],
318 'function_type': 'ttt',
319 'values' : [
320 [1.0, 2 ** 0.95, 2 ** pi, 2 ** -pi, float("inf"), float.fromhex('0x1.146b7fd8431e3p+3')], # Result
321 [0.0, 0.95, pi, -pi, float("inf"), float.fromhex('0x1.8e2cp+1')] # Arg0
323 'tolerance' : 3
325 'expm1' : {
326 'arg_types' : [F, F],
327 'function_type': 'ttt',
328 'values' : [
329 [0.0, expm1(0.95), expm1(pi), expm1(-pi), float("inf"), float.fromhex('0x1.56fe8a160893ep+4')], # Result
330 [0.0, 0.95, pi, -pi, float("inf"), float.fromhex('0x1.8e2cp+1')] # Arg0
332 'tolerance' : 3
334 'fabs' : {
335 'arg_types' : [F, F],
336 'function_type': 'ttt',
337 'values' : [
338 [0.0, pi/2, pi, 0.0, float("inf"), float("inf"), 1.12345 ], # Result
339 [0.0, -pi/2, pi, -0.0, float("-inf"), float("inf"), -1.12345] # Arg0
341 'tolerance' : 0
343 'fdim' : {
344 'arg_types' : [F, F, F],
345 'function_type': 'ttt',
346 'values' : [
347 [0.0, 0.75, 0.0, 0.0, float("inf"), 0.0, float("nan"), float("nan"), float("nan"), 2.2469 ], # Result
348 [0.3, 1.0, pi, 0.0, float("inf"), float("inf"), float("nan"), 1.0, float("nan"), 1.12345 ], # Arg0
349 [1.5, 0.25, pi, -0.0, float("-inf"), float("inf"), float("nan"), float("nan"), 1.0, -1.12345] # Arg1
352 'floor' : {
353 'arg_types': [F, F],
354 'function_type': 'ttt',
355 'values': [
356 [0.0, -1.0, 0.0, -0.0, float("nan"), -4.0, 1.0],
357 [0.5, -0.5, 0.0, -0.0, float("nan"), -3.99, 1.5]
360 'fma' : {
361 'arg_types': [F, F, F, F],
362 'function_type': 'tss',
363 'values': [
364 [pi, 1.0, pi , -0.5, float("nan"), float("nan"), float("nan")], # Result
365 [1.0, pi, 0.0, 0.0, 1.0, float("nan"), float("nan")], # Arg0
366 [pi, 0.0, pi, -0.5, float("nan"), 1.0, float("nan")], # Arg1
367 [0.0, 1.0, pi, -0.5, float("nan"), 1.0, float("nan")] # Arg2
370 'fmax' : {
371 'arg_types': [F, F, F],
372 'function_type': 'tss',
373 'values': [
374 [1.0, 0.0, 0.0, 0.0, 1.0, 1.0, float("nan")], #Result
375 [1.0, -0.5, 0.0, 0.0, 1.0, float("nan"), float("nan")], #Arg0
376 [0.0, 0.0, 0.0, -0.5, float("nan"), 1.0, float("nan")] #Arg1
379 'fmin' : {
380 'arg_types': [F, F, F],
381 'function_type': 'tss',
382 'values': [
383 [0.0, -0.5, 0.0, -0.5, 1.0, 1.0, float("nan")], #Result
384 [1.0, -0.5, 0.0, 0.0, 1.0, float("nan"), float("nan")], #Arg0
385 [0.0, 0.0, 0.0, -0.5, float("nan"), 1.0, float("nan")] #Arg1
388 'fmod' : {
389 'arg_types': [F, F, F],
390 'function_type': 'ttt',
391 'values': [
392 [float.fromhex("0x1.99998p-4"), float("nan"), float.fromhex("-0x1.47aep-7"), 1.0, float("-nan"), float("nan")],
393 [float.fromhex("0x1.466666p+2"), 0.0, float.fromhex("-0x1p+2"), 1.0, 5.1, 3.0 ],
394 [float.fromhex("0x1p-1"), float("nan"), float.fromhex("-0x1.feb852p+1"), 1.5, 0.0, float("inf")]
396 'tolerance' : 0
398 'fract' : {
399 'arg_types': [F, F, F],
400 'function_type': 'ttt',
401 # For fract we have two outputs per address space.
402 'values': [
403 [float("nan"), 0.0, 0.5, 0.0, float.fromhex('0x1.33333p-2'), float.fromhex('0x1.fffffep-1') ], #fract
404 [float("nan"), float("inf"), 1.0, 2.0, -2.0, -1.0], #floor
405 [float("nan"), float("inf"), 1.5, 2.0,float.fromhex('-0x1.b33334p+0'), float.fromhex('-0x1.000242p-24')] #src0
407 'num_out_args' : 2
409 'frexp' : {
410 'arg_types': [F, I, F],
411 'function_type': 'ttt',
412 # For frexp we have two outputs per address space.
413 'values': [
414 [0.602783203125, 0.5, float("nan"), float("nan"), float("inf"), float("-inf"), 0.0],
415 [11, 1, 0, 0, 0, 0, 0],
416 [1234.5, 1.0, float("nan"), float("-nan"), float("inf"), float("-inf"), 0.0]
418 'num_out_args' : 2
420 'hypot' : {
421 'arg_types': [F, F, F],
422 'function_type': 'ttt',
423 'values': [
424 [hypot(0, 1.0), hypot(3, 10.0), hypot(1, -3.0), hypot(10, 1234.5), hypot(2147483647, -1.0), float("inf")], # Result
425 [0, 3, 1, 10, 2147483647, 2147483647], # Arg0
426 [1.0, 10.0, -3.0, 1234.5, -1.0, float("-inf")] # Arg1
428 'tolerance' : 4
430 'ilogb' : {
431 'arg_types': [I, F],
432 'function_type': 'ttt',
433 'values': [
434 [0, 3, 1, 10, 2147483647, 2147483647],
435 [1.0, 10.0, -3.0, 1234.5, float("inf"), float("-inf")]
437 'tolerance' : 0
439 'ldexp' : {
440 'arg_types': [F, F, I],
441 'function_type': 'tss',
442 'values': [
443 [0.0, 4.0, 15.2, 1.75, float("nan"), float("inf")],
444 [0.0, 1.0, 0.95, 3.5, float("nan"), 1.12312312],
445 [0, 2, 4, -1, 1, 2031231231]
447 'tolerance' : 0
449 'lgamma' : {
450 'arg_types': [F, F],
451 'function_type': 'ttt',
452 'values': [
453 [0.0, lgamma(1.5), lgamma(0.5), float("nan"), lgamma(1.e-15), float("nan")], # Result
454 [1.0, 1.5, 0.5, 0.0, 1.e-15, float("nan")] # Arg
456 'tolerance' : 16777216 # Specs say it's currently undefined
458 'lgamma_r' : {
459 'arg_types': [F, I, F],
460 'function_type': 'ttt',
461 'values': [
462 [0.0, lgamma(1.5), lgamma(0.5), float("nan"), lgamma(1.e-15), float("nan")], # Result0
463 [1, -1, 1, 1, 1, 1], # Result1
464 [1.0, 1.5, 0.5, 0.0, 1.e-15, float("nan")] # Arg
466 'tolerance' : 16777216, # Specs say it's currently undefined
467 'num_out_args' : 2
469 'log' : {
470 'arg_types': [F, F],
471 'function_type': 'ttt',
472 'values': [
473 [log(0.5), float("-inf"), log(1.e-15), float("nan")], #Result
474 [0.5, 0.0, 1.e-15, float("nan")] #Arg0
476 'tolerance' : 3
478 'log10' : {
479 'arg_types': [F, F],
480 'function_type': 'ttt',
481 'values': [
482 [log10(0.5), float("-inf"), log10(1.e-15), float("nan")],
483 [0.5, 0.0, 1.e-15, float("nan")]
485 'tolerance' : 3
487 'log1p' : {
488 'arg_types': [F, F],
489 'function_type': 'ttt',
490 'values': [
491 [log1p(0.5), float("-inf"), log1p(1.e-15), float("nan")],
492 [0.5, -1.0, 1.e-15, float("nan")]
494 'tolerance' : 2
496 'log2' : {
497 'arg_types': [F, F],
498 'function_type': 'ttt',
499 'values': [
500 [log(0.5, 2), float("-inf"), log(1.e-15, 2), float("nan")], #Result
501 [0.5, 0.0, 1.e-15, float("nan")] #Arg0
503 'tolerance' : 3
505 'logb' : {
506 'arg_types': [F, F],
507 'function_type': 'ttt',
508 'values': [
509 [0, 3, 1, 10, float("inf"), float("inf")], #Result
510 [1.0, 10.0, -3.0, 1234.5, float("inf"), float("-inf")] #Arg0
512 'tolerance' : 0
514 'mad' : {
515 'arg_types': [F, F, F, F],
516 'function_type': 'tss',
517 'values': [
518 [pi, 1.0, pi , -0.5, float("nan"), float("nan"), float("nan")], # Result
519 [1.0, pi, 0.0, 0.0, 1.0, float("nan"), float("nan")], # Arg0
520 [pi, 0.0, pi, -0.5, float("nan"), 1.0, float("nan")], # Arg1
521 [0.0, 1.0, pi, -0.5, float("nan"), 1.0, float("nan")] # Arg2
523 'tolerance' : 16777216 #infinite ULP
525 'maxmag' : {
526 'arg_types': [F, F, F],
527 'function_type': 'ttt',
528 'values': [
529 [1.0, -0.5, 0.0, -0.5, 1.0, 1.0, float("nan")], #Result
530 [1.0, -0.5, 0.0, 0.0, 1.0, float("nan"), float("nan")], #Arg0
531 [0.0, 0.0, 0.0, -0.5, float("nan"), 1.0, float("nan")] #Arg1
534 'minmag' : {
535 'arg_types': [F, F, F],
536 'function_type': 'ttt',
537 'values': [
538 [0.0, -0.5, 0.0, 1.0, 1.0, 1.0, float("nan")], #Result
539 [1.0, -0.5, 1.0, 1.0, 1.0, float("nan"), float("nan")], #Arg0
540 [0.0, 1.0, 0.0, -1.5, float("nan"), 1.0, float("nan")] #Arg1
543 'modf' : {
544 'arg_types': [F, F, F],
545 'function_type': 'ttt',
546 'values': [
547 [0.0, modf(1.5)[0], modf(0.25)[0], 0.0, modf(1.e-15)[0], float("nan")], # Result0
548 [1, modf(1.5)[1], modf(0.25)[1], 0.0, modf(1.e-15)[1], float("nan")], # Result1
549 [1.0, 1.5, 0.25, 0.0, 1.e-15, float("nan")] # Arg
551 'num_out_args' : 2
553 # FIXME: kernel names are broken, and we cant really compare nans to see if the
554 # code made it
555 # 'nan' : {
556 # 'arg_types': [F, U],
557 # 'function_type': 'ttt',
558 # 'values': [
559 # [float("nan"), float("nan"), float("nan")],
560 # [0xdead, 0xadbeef, 0xdead]
561 # ],
562 # 'tolerance' : 0
563 # },
564 'nextafter' : {
565 'arg_types': [F, F, F],
566 'function_type': 'ttt',
567 'values': [
568 [1.401298e-45, -1.401298e-45, 1.00000011920928955078125, 0.999999940395355224609375, float("nan"), float("nan"), 5.0 ], # Result
569 [0.0, 0.0 , 1.0, 1.0, float("nan"), 2.5, 5.0], # Arg0
570 [1.0, -1.0 , 2.0, 0.0, 3.4, float("nan"), 5.0], # Arg1
573 'pow' : {
574 'arg_types': [F, F, F],
575 'function_type': 'ttt',
576 'values': [
577 [pow(0, 1.0), pow(-3, 10.0), pow(-11, -3.0), pow(1234.5, 10), pow(2147483647, -1.0), float("inf")], # Result
578 [0, -3, -11, 1234.5, 2147483647, 2147483647], # Arg0
579 [1.0, 10.0, -3.0, 10, -1.0, float("-inf")] # Arg1
581 'tolerance' : 16
583 'pown' : {
584 'arg_types': [F, F, I],
585 'function_type': 'ttt',
586 'values': [
587 [pow(1, 0), pow(10.0, 3), pow(-3.3, -4), pow(1234, 10), pow(-1, 2147483647), float("-inf")], # Result
588 [1.0, 10.0, -3.3, 1234, -1.0, float("-inf")], # Arg0
589 [0, 3, -4, 10, 2147483647, 2147483647] # Arg1
591 'tolerance' : 16
593 'powr' : {
594 'arg_types': [F, F, F],
595 'function_type': 'ttt',
596 'values': [
597 [pow(0, 1.0), pow(3, 10.0), pow(11, -3.0), pow(1234.5, 10), pow(2147483647, -1.0), 0.0], # Result
598 [0, 3, 11, 1234.5, 2147483647, 2147483647], # Arg0
599 [1.0, 10.0, -3.0, 10, -1.0, float("-inf")] # Arg1
601 'tolerance' : 16
603 'remainder' : {
604 'arg_types': [F, F, F],
605 'function_type': 'ttt',
606 'values': [
607 [float.fromhex("-0x1.ccccdp-1"), float.fromhex("0x1.ccccdp-1"),
608 float.fromhex("-0x1.ccccdp-1"), float.fromhex("0x1.ccccdp-1"),
609 0.0, -0.0, 5.1, float("-nan")
610 ], # Result
611 [ 5.1, -5.1, 5.1, -5.1, 0.0, -0.0, 5.1, 5.1], # Arg0
612 [ 3.0, 3.0, -3.0, -3.0, 1.0, 1.0, float("inf"), 0.0], # Arg1
615 'remquo' : {
616 'arg_types': [F, I, F, F],
617 'function_type': 'ttt',
618 'values': [
619 [float.fromhex("-0x1.ccccdp-1"), float.fromhex("0x1.ccccdp-1"),
620 float.fromhex("-0x1.ccccdp-1"), float.fromhex("0x1.ccccdp-1"),
621 0.0, -0.0, 5.1, float("-nan")
622 ], # Result
623 [quo(5.1, 3.0), quo(-5.1, 3.0), quo(5.1, -3.0), quo(-5.1, -3.0),
624 quo(0.0, 1.0), quo(-0.0, 1.0), quo(5.1, float("inf")), 0], # Arg0
625 [ 5.1, -5.1, 5.1, -5.1, 0.0, -0.0, 5.1, 5.1], # Arg0
626 [ 3.0, 3.0, -3.0, -3.0, 1.0, 1.0, float("inf"), 0.0], # Arg1
628 'num_out_args' : 2
630 'rint' : {
631 'arg_types': [F, F],
632 'function_type': 'ttt',
633 'values': [
634 [0.0, -0.0, 1.0, -1.0, float("nan"), -4.0, 2.0, 0.0, 1.0],
635 [0.5, -0.5, 0.6, -0.6, float("nan"), -3.99, 1.5, 0.4, 0.6]
638 'rootn' : {
639 'arg_types': [F, F, I],
640 'function_type': 'ttt',
641 'values': [
642 [pow(1, 1/2), pow(10.0, 1/3), float("nan"), pow(1234, 1/10), -1, float("-inf")], # Result
643 [1.0, 10.0, -3.3, 1234, -1.0, float("-inf")], # Arg0
644 [2, 3, -4, 10, 2147483647, 2147483647] # Arg1
646 'tolerance' : 16
648 'round' : {
649 'arg_types': [F, F],
650 'function_type': 'ttt',
651 'values': [
652 [1.0, -1.0, 0.0, -0.0, float("nan"), -4.0, 2.0, 0.0, 1.0],
653 [0.5, -0.5, 0.0, -0.0, float("nan"), -3.99, 1.5, 0.4, 0.6]
656 'rsqrt' : {
657 'arg_types': [F, F],
658 'function_type': 'ttt',
659 'values': [
660 [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
661 [1.0, 4.0, 36.0, 6.25, float("nan"), 16.0, 0.0, 7.0, pi], # Arg1
663 'tolerance': 2
665 'sin' : {
666 'arg_types' : [F, F],
667 'function_type': 'ttt',
668 'values' : [
669 [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
670 [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
672 'tolerance': 4
674 'sincos' : {
675 'arg_types' : [F, F, F],
676 'function_type': 'ttt',
677 'values' : [
678 [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
679 # using libm cosf(3.0f * M_PI / 2.0f) == 0x1.99bc5cp-27
680 # this is different form what python gives us
681 [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
682 [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
684 'tolerance': 4,
685 'num_out_args' : 2
687 'sinh' : {
688 'arg_types' : [F, F],
689 'function_type': 'ttt',
690 'values' : [
691 [0.0, sinh(0.123456789), float("inf"), float("-inf"), float("nan")],# Result
692 [0.0, 0.123456789, float("inf"), float("-inf"), float("nan")] # Arg0
694 'tolerance': 4
696 'sinpi' : {
697 'arg_types' : [F, F],
698 'function_type': 'ttt',
699 'values' : [
700 [0.0, 0.0, sin(pi*pi/2), sin(pi*3*pi/2), sin(2* M_PI_F * pi),
701 sin(pi*1.12345), 0.0, 0.0, 0.0, 0.0, 0.0, float("nan")],#Result
702 [0.0, 1.0, pi / 2, 3 * pi / 2, 2 * pi,
703 1.12345 , 7.0, 8.0, pow(2,20), pow(2,24), pow(2,120),
704 float("nan")] #Arg0
706 'tolerance' : 4
708 'sqrt' : {
709 'arg_types': [F, F],
710 'function_type': 'ttt',
711 'values': [
712 [1.0, 2.0, 6.0, 2.5 , float("nan"), 4.0, sqrt(0.0), sqrt(7.0), sqrt(pi)], # Result
713 [1.0, 4.0, 36.0, 6.25, float("nan"), 16.0, 0.0, 7.0, pi], # Arg1
715 'tolerance': 3
717 'tan' : {
718 'arg_types': [F, F],
719 'function_type': 'ttt',
720 'values': [
721 [0.0, 1.0, tan(M_PI_F), sqrt(3), -1.0, tan(2.234567), float("nan") ], # Result
722 [0.0, pi/4, M_PI_F, pi/3, 3*pi/4, 2.234567 , float("nan") ], # Arg1
724 'tolerance': 5
726 'tanh' : {
727 'arg_types' : [F, F],
728 'function_type': 'ttt',
729 'values' : [
730 [0.0, tanh(0.123456789), tanh(15.123456789), 1.0, -1.0 , float("nan")],# Result
731 [0.0, 0.123456789, 15.123456789, float("inf"), float("-inf"), float("nan")] # Arg0
733 'tolerance': 5
735 'tanpi' : {
736 'arg_types': [F, F],
737 'function_type': 'ttt',
738 'values': [
739 #fp32 representation of 2.234567 is 0x1.1e064ap+1
740 [0.0, 1.0, 0.0, sqrt(3), -1.0, tan(M_PI_F * float.fromhex('0x1.1e064ap+1')), float("nan") ], # Result
741 [0.0, 1/4, 1, 1/3, 3/4, 2.234567, float("nan") ], # Arg1
743 'tolerance': 6
745 'tgamma' : {
746 'arg_types': [F, F],
747 'function_type': 'ttt',
748 'values': [
749 [1.0, gamma(1.5), gamma(0.5), float("nan"), gamma(1.e-15), float("nan")], # Result
750 [1.0, 1.5, 0.5, 0.0, 1.e-15, float("nan")] # Arg
752 'tolerance' : 16
754 'trunc' : {
755 'arg_types': [F, F],
756 'function_type': 'ttt',
757 'values': [
758 [0.0, -0.0, 0.0, -0.0, float("nan"), -3.0, 1.0],
759 [0.5, -0.5, 0.0, -0.0, float("nan"), -3.99, 1.5]
765 def main():
766 dirName = os.path.join("cl", "builtin", "math")
768 testDefs = {}
769 functions = sorted(tests.keys())
770 for dataType in DATA_TYPES:
771 for fnName in functions:
772 testDefs[(dataType, fnName)] = tests[fnName]
774 gen(DATA_TYPES, CLC_VERSION_MIN, functions, testDefs, dirName)
777 if __name__ == '__main__':
778 main()