12
12
// This header defines device-side overloads of <complex> functions.
13
13
14
14
#ifdef __SYCL_DEVICE_ONLY__
15
- #include < cmath> // For INFINITY.
15
+
16
+ #include < limits>
16
17
17
18
// The 'sycl_device_only' attribute enables device-side overloading.
18
19
#define __SYCL_DEVICE __attribute__ ((sycl_device_only, always_inline))
@@ -82,8 +83,9 @@ float __complex__ __mulsc3(float __a, float __b, float __c, float __d) {
82
83
__recalc = 1 .0f ;
83
84
}
84
85
if (__recalc) {
85
- z = __SYCL_CMPLXF ((INFINITY * (__a * __c - __b * __d)),
86
- (INFINITY * (__a * __d + __b * __c)));
86
+ z = __SYCL_CMPLXF (
87
+ (std::numeric_limits<float >::infinity () * (__a * __c - __b * __d)),
88
+ (std::numeric_limits<float >::infinity () * (__a * __d + __b * __c)));
87
89
}
88
90
}
89
91
return z;
@@ -131,8 +133,9 @@ double __complex__ __muldc3(double __a, double __b, double __c, double __d) {
131
133
__recalc = 1.0 ;
132
134
}
133
135
if (__recalc) {
134
- z = __SYCL_CMPLX ((INFINITY * (__a * __c - __b * __d)),
135
- (INFINITY * (__a * __d + __b * __c)));
136
+ z = __SYCL_CMPLX (
137
+ (std::numeric_limits<float >::infinity () * (__a * __c - __b * __d)),
138
+ (std::numeric_limits<float >::infinity () * (__a * __d + __b * __c)));
136
139
}
137
140
}
138
141
return z;
@@ -161,15 +164,19 @@ float __complex__ __divsc3(float __a, float __b, float __c, float __d) {
161
164
z = __SYCL_CMPLXF (z_real, z_imag);
162
165
if (__spirv_IsNan (z_real) && __spirv_IsNan (z_imag)) {
163
166
if ((__denom == 0 .0f ) && (!__spirv_IsNan (__a) || !__spirv_IsNan (__b))) {
164
- z_real = __spirv_ocl_copysign (INFINITY, __c) * __a;
165
- z_imag = __spirv_ocl_copysign (INFINITY, __c) * __b;
167
+ z_real =
168
+ __spirv_ocl_copysign (std::numeric_limits<float >::infinity (), __c) *
169
+ __a;
170
+ z_imag =
171
+ __spirv_ocl_copysign (std::numeric_limits<float >::infinity (), __c) *
172
+ __b;
166
173
z = __SYCL_CMPLXF (z_real, z_imag);
167
174
} else if ((__spirv_IsInf (__a) || __spirv_IsInf (__b)) &&
168
175
__spirv_IsFinite (__c) && __spirv_IsFinite (__d)) {
169
176
__a = __spirv_ocl_copysign (__spirv_IsInf (__a) ? 1 .0f : 0 .0f , __a);
170
177
__b = __spirv_ocl_copysign (__spirv_IsInf (__b) ? 1 .0f : 0 .0f , __b);
171
- z_real = INFINITY * (__a * __c + __b * __d);
172
- z_imag = INFINITY * (__b * __c - __a * __d);
178
+ z_real = std::numeric_limits< float >:: infinity () * (__a * __c + __b * __d);
179
+ z_imag = std::numeric_limits< float >:: infinity () * (__b * __c - __a * __d);
173
180
z = __SYCL_CMPLXF (z_real, z_imag);
174
181
} else if (__spirv_IsInf (__logbw) && __logbw > 0 .0f &&
175
182
__spirv_IsFinite (__a) && __spirv_IsFinite (__b)) {
@@ -203,15 +210,19 @@ double __complex__ __divdc3(double __a, double __b, double __c, double __d) {
203
210
z = __SYCL_CMPLX (z_real, z_imag);
204
211
if (__spirv_IsNan (z_real) && __spirv_IsNan (z_imag)) {
205
212
if ((__denom == 0.0 ) && (!__spirv_IsNan (__a) || !__spirv_IsNan (__b))) {
206
- z_real = __spirv_ocl_copysign ((double )INFINITY, __c) * __a;
207
- z_imag = __spirv_ocl_copysign ((double )INFINITY, __c) * __b;
213
+ z_real =
214
+ __spirv_ocl_copysign (std::numeric_limits<double >::infinity (), __c) *
215
+ __a;
216
+ z_imag =
217
+ __spirv_ocl_copysign (std::numeric_limits<double >::infinity (), __c) *
218
+ __b;
208
219
z = __SYCL_CMPLX (z_real, z_imag);
209
220
} else if ((__spirv_IsInf (__a) || __spirv_IsInf (__b)) &&
210
221
__spirv_IsFinite (__c) && __spirv_IsFinite (__d)) {
211
222
__a = __spirv_ocl_copysign (__spirv_IsInf (__a) ? 1.0 : 0.0 , __a);
212
223
__b = __spirv_ocl_copysign (__spirv_IsInf (__b) ? 1.0 : 0.0 , __b);
213
- z_real = INFINITY * (__a * __c + __b * __d);
214
- z_imag = INFINITY * (__b * __c - __a * __d);
224
+ z_real = std::numeric_limits< float >:: infinity () * (__a * __c + __b * __d);
225
+ z_imag = std::numeric_limits< float >:: infinity () * (__b * __c - __a * __d);
215
226
z = __SYCL_CMPLX (z_real, z_imag);
216
227
} else if (__spirv_IsInf (__logbw) && __logbw > 0.0 &&
217
228
__spirv_IsFinite (__a) && __spirv_IsFinite (__b)) {
@@ -247,14 +258,16 @@ __SYCL_DEVICE_C
247
258
float __complex__ cprojf (float __complex__ z) {
248
259
float __complex__ r = z;
249
260
if (__spirv_IsInf (crealf (z)) || __spirv_IsInf (cimagf (z)))
250
- r = __SYCL_CMPLXF (INFINITY, __spirv_ocl_copysign (0 .0f , cimagf (z)));
261
+ r = __SYCL_CMPLXF (std::numeric_limits<float >::infinity (),
262
+ __spirv_ocl_copysign (0 .0f , cimagf (z)));
251
263
return r;
252
264
}
253
265
__SYCL_DEVICE_C
254
266
double __complex__ cproj (double __complex__ z) {
255
267
double __complex__ r = z;
256
268
if (__spirv_IsInf (creal (z)) || __spirv_IsInf (cimag (z)))
257
- r = __SYCL_CMPLX (INFINITY, __spirv_ocl_copysign (0.0 , cimag (z)));
269
+ r = __SYCL_CMPLX (std::numeric_limits<float >::infinity (),
270
+ __spirv_ocl_copysign (0.0 , cimag (z)));
258
271
return r;
259
272
}
260
273
@@ -275,7 +288,7 @@ float __complex__ cexpf(float __complex__ z) {
275
288
return z;
276
289
} else if (z_imag == 0 .f || !__spirv_IsFinite (z_imag)) {
277
290
if (__spirv_IsInf (z_imag))
278
- return __SYCL_CMPLXF (z_real, NAN );
291
+ return __SYCL_CMPLXF (z_real, std::numeric_limits< float >:: quiet_NaN () );
279
292
}
280
293
}
281
294
@@ -293,16 +306,18 @@ double __complex__ cexp(double __complex__ z) {
293
306
z_imag = 1.0 ;
294
307
} else if (z_imag == 0.0 || !__spirv_IsFinite (z_imag)) {
295
308
if (__spirv_IsInf (z_imag))
296
- z_imag = NAN ;
309
+ z_imag = std::numeric_limits< float >:: quiet_NaN () ;
297
310
return __SYCL_CMPLX (z_real, z_imag);
298
311
}
299
312
} else if (__spirv_IsNan (z_real)) {
300
313
if (z_imag == 0.0 )
301
314
return z;
302
- return __SYCL_CMPLX (NAN, NAN);
315
+ return __SYCL_CMPLX (std::numeric_limits<float >::quiet_NaN (),
316
+ std::numeric_limits<float >::quiet_NaN ());
303
317
} else if (__spirv_IsFinite (z_real) &&
304
318
(__spirv_IsNan (z_imag) || __spirv_IsInf (z_imag))) {
305
- return __SYCL_CMPLX (NAN, NAN);
319
+ return __SYCL_CMPLX (std::numeric_limits<float >::quiet_NaN (),
320
+ std::numeric_limits<float >::quiet_NaN ());
306
321
}
307
322
double __e = __spirv_ocl_exp (z_real);
308
323
double ret_real = __e * __spirv_ocl_cos (z_imag);
@@ -354,16 +369,18 @@ double __complex__ cpow(double __complex__ x, double __complex__ y) {
354
369
__SYCL_DEVICE_C
355
370
float __complex__ cpolarf (float rho, float theta) {
356
371
if (__spirv_IsNan (rho) || __spirv_SignBitSet (rho))
357
- return __SYCL_CMPLXF (NAN, NAN);
372
+ return __SYCL_CMPLXF (std::numeric_limits<float >::quiet_NaN (),
373
+ std::numeric_limits<float >::quiet_NaN ());
358
374
if (__spirv_IsNan (theta)) {
359
375
if (__spirv_IsInf (rho))
360
376
return __SYCL_CMPLXF (rho, theta);
361
377
return __SYCL_CMPLXF (theta, theta);
362
378
}
363
379
if (__spirv_IsInf (theta)) {
364
380
if (__spirv_IsInf (rho))
365
- return __SYCL_CMPLXF (rho, NAN);
366
- return __SYCL_CMPLXF (NAN, NAN);
381
+ return __SYCL_CMPLXF (rho, std::numeric_limits<float >::quiet_NaN ());
382
+ return __SYCL_CMPLXF (std::numeric_limits<float >::quiet_NaN (),
383
+ std::numeric_limits<float >::quiet_NaN ());
367
384
}
368
385
float x = rho * __spirv_ocl_cos (theta);
369
386
if (__spirv_IsNan (x))
@@ -376,16 +393,18 @@ float __complex__ cpolarf(float rho, float theta) {
376
393
__SYCL_DEVICE_C
377
394
double __complex__ cpolar (double rho, double theta) {
378
395
if (__spirv_IsNan (rho) || __spirv_SignBitSet (rho))
379
- return __SYCL_CMPLX (NAN, NAN);
396
+ return __SYCL_CMPLX (std::numeric_limits<float >::quiet_NaN (),
397
+ std::numeric_limits<float >::quiet_NaN ());
380
398
if (__spirv_IsNan (theta)) {
381
399
if (__spirv_IsInf (rho))
382
400
return __SYCL_CMPLX (rho, theta);
383
401
return __SYCL_CMPLX (theta, theta);
384
402
}
385
403
if (__spirv_IsInf (theta)) {
386
404
if (__spirv_IsInf (rho))
387
- return __SYCL_CMPLX (rho, NAN);
388
- return __SYCL_CMPLX (NAN, NAN);
405
+ return __SYCL_CMPLX (rho, std::numeric_limits<float >::quiet_NaN ());
406
+ return __SYCL_CMPLX (std::numeric_limits<float >::quiet_NaN (),
407
+ std::numeric_limits<float >::quiet_NaN ());
389
408
}
390
409
double x = rho * __spirv_ocl_cos (theta);
391
410
if (__spirv_IsNan (x))
@@ -401,7 +420,7 @@ float __complex__ csqrtf(float __complex__ z) {
401
420
float z_real = crealf (z);
402
421
float z_imag = cimagf (z);
403
422
if (__spirv_IsInf (z_imag))
404
- return __SYCL_CMPLXF (INFINITY , z_imag);
423
+ return __SYCL_CMPLXF (std::numeric_limits< float >:: infinity () , z_imag);
405
424
if (__spirv_IsInf (z_real)) {
406
425
if (z_real > 0 .0f )
407
426
return __SYCL_CMPLXF (z_real, __spirv_IsNan (z_imag)
@@ -417,7 +436,7 @@ double __complex__ csqrt(double __complex__ z) {
417
436
double z_real = creal (z);
418
437
double z_imag = cimag (z);
419
438
if (__spirv_IsInf (z_imag))
420
- return __SYCL_CMPLX (INFINITY , z_imag);
439
+ return __SYCL_CMPLX (std::numeric_limits< float >:: infinity () , z_imag);
421
440
if (__spirv_IsInf (z_real)) {
422
441
if (z_real > 0.0 )
423
442
return __SYCL_CMPLX (z_real, __spirv_IsNan (z_imag)
@@ -434,9 +453,9 @@ float __complex__ csinhf(float __complex__ z) {
434
453
float z_real = crealf (z);
435
454
float z_imag = cimagf (z);
436
455
if (__spirv_IsInf (z_real) && !__spirv_IsFinite (z_imag))
437
- return __SYCL_CMPLXF (z_real, NAN );
456
+ return __SYCL_CMPLXF (z_real, std::numeric_limits< float >:: quiet_NaN () );
438
457
if (z_real == 0 && !__spirv_IsFinite (z_imag))
439
- return __SYCL_CMPLXF (z_real, NAN );
458
+ return __SYCL_CMPLXF (z_real, std::numeric_limits< float >:: quiet_NaN () );
440
459
if (z_imag == 0 && !__spirv_IsFinite (z_real))
441
460
return z;
442
461
return __SYCL_CMPLXF (__spirv_ocl_sinh (z_real) * __spirv_ocl_cos (z_imag),
@@ -447,9 +466,9 @@ double __complex__ csinh(double __complex__ z) {
447
466
double z_real = creal (z);
448
467
double z_imag = cimag (z);
449
468
if (__spirv_IsInf (z_real) && !__spirv_IsFinite (z_imag))
450
- return __SYCL_CMPLX (z_real, NAN );
469
+ return __SYCL_CMPLX (z_real, std::numeric_limits< float >:: quiet_NaN () );
451
470
if (z_real == 0 && !__spirv_IsFinite (z_imag))
452
- return __SYCL_CMPLX (z_real, NAN );
471
+ return __SYCL_CMPLX (z_real, std::numeric_limits< float >:: quiet_NaN () );
453
472
if (z_imag == 0 && !__spirv_IsFinite (z_real))
454
473
return z;
455
474
return __SYCL_CMPLX (__spirv_ocl_sinh (z_real) * __spirv_ocl_cos (z_imag),
@@ -461,9 +480,10 @@ float __complex__ ccoshf(float __complex__ z) {
461
480
float z_real = crealf (z);
462
481
float z_imag = cimagf (z);
463
482
if (__spirv_IsInf (z_real) && !__spirv_IsFinite (z_imag))
464
- return __SYCL_CMPLXF (__spirv_ocl_fabs (z_real), NAN);
483
+ return __SYCL_CMPLXF (__spirv_ocl_fabs (z_real),
484
+ std::numeric_limits<float >::quiet_NaN ());
465
485
if (z_real == 0 && !__spirv_IsFinite (z_imag))
466
- return __SYCL_CMPLXF (NAN , z_real);
486
+ return __SYCL_CMPLXF (std::numeric_limits< float >:: quiet_NaN () , z_real);
467
487
if (z_real == 0 && z_imag == 0 )
468
488
return __SYCL_CMPLXF (1 .0f , z_imag);
469
489
if (z_imag == 0 && !__spirv_IsFinite (z_real))
@@ -476,9 +496,10 @@ double __complex__ ccosh(double __complex__ z) {
476
496
double z_real = creal (z);
477
497
double z_imag = cimag (z);
478
498
if (__spirv_IsInf (z_real) && !__spirv_IsFinite (z_imag))
479
- return __SYCL_CMPLX (__spirv_ocl_fabs (z_real), NAN);
499
+ return __SYCL_CMPLX (__spirv_ocl_fabs (z_real),
500
+ std::numeric_limits<float >::quiet_NaN ());
480
501
if (z_real == 0 && !__spirv_IsFinite (z_imag))
481
- return __SYCL_CMPLX (NAN , z_real);
502
+ return __SYCL_CMPLX (std::numeric_limits< float >:: quiet_NaN () , z_real);
482
503
if (z_real == 0 && z_imag == 0 )
483
504
return __SYCL_CMPLX (1 .0f , z_imag);
484
505
if (z_imag == 0 && !__spirv_IsFinite (z_real))
@@ -790,8 +811,9 @@ float __complex__ catanhf(float __complex__ z) {
790
811
return __SYCL_CMPLXF (__spirv_ocl_copysign (0 .0f , z_real),
791
812
__spirv_ocl_copysign (__pi / 2 .0f , z_imag));
792
813
if (__spirv_ocl_fabs (z_real) == 1 .0f && z_imag == 0 .0f )
793
- return __SYCL_CMPLXF (__spirv_ocl_copysign (INFINITY, z_real),
794
- __spirv_ocl_copysign (0 .0f , z_imag));
814
+ return __SYCL_CMPLXF (
815
+ __spirv_ocl_copysign (std::numeric_limits<float >::infinity (), z_real),
816
+ __spirv_ocl_copysign (0 .0f , z_imag));
795
817
float __complex__ t1 = 1 .0f + z;
796
818
float __complex__ t2 = 1 .0f - z;
797
819
float __complex__ t3 =
@@ -820,7 +842,7 @@ double __complex__ catanh(double __complex__ z) {
820
842
__spirv_ocl_copysign (__pi / 2.0 , z_imag));
821
843
if (__spirv_ocl_fabs (z_real) == 1.0 && z_imag == 0.0 )
822
844
return __SYCL_CMPLX (
823
- __spirv_ocl_copysign (static_cast <double >(INFINITY ), z_real),
845
+ __spirv_ocl_copysign (std::numeric_limits <double >:: infinity ( ), z_real),
824
846
__spirv_ocl_copysign (0.0 , z_imag));
825
847
double __complex__ t1 = 1.0 + z;
826
848
double __complex__ t2 = 1.0 - z;
0 commit comments