Skip to content

Commit 5dc1f88

Browse files
committed
Fix failed corner cases on Linux platform
Signed-off-by: jinge90 <[email protected]>
1 parent f898b54 commit 5dc1f88

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

libdevice/fallback-complex.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,24 @@ DEVICE_EXTERN_C_INLINE
141141
float __complex__ __devicelib_cexpf(float __complex__ z) {
142142
float z_imag = __devicelib_cimagf(z);
143143
float z_real = __devicelib_crealf(z);
144+
if (z_imag == 0) {
145+
return CMPLXF(__spirv_ocl_exp(z_real), __spirv_ocl_copysign(0.f, z_imag));
146+
}
147+
144148
if (__spirv_IsInf(z_real)) {
145-
if (z_real < 0.0f) {
149+
if (z_real < 0.f) {
146150
if (!__spirv_IsFinite(z_imag))
147151
z_imag = 1.0f;
148-
} else if (z_imag == 0.0f || !__spirv_IsFinite(z_imag)) {
152+
} else if (__spirv_IsNan(z_imag)) {
153+
return z;
154+
} else if (z_imag == 0.f || !__spirv_IsFinite(z_imag)) {
149155
if (__spirv_IsInf(z_imag))
150-
z_imag = NAN;
151-
return CMPLXF(z_real, z_imag);
156+
return CMPLXF(z_real, NAN);
152157
}
153-
} else if (__spirv_IsNan(z_real)) {
154-
if (z_imag == 0.0f)
155-
return z;
156-
return CMPLX(NAN, NAN);
157-
} else if (__spirv_IsFinite(z_real) &&
158-
(__spirv_IsNan(z_imag) || __spirv_IsInf(z_imag))) {
159-
return CMPLX(NAN, NAN);
160158
}
161-
float __e = __spirv_ocl_exp(z_real);
162-
float ret_real = __e * __spirv_ocl_cos(z_imag);
163-
float ret_imag = __e * __spirv_ocl_sin(z_imag);
164159

165-
if (__spirv_IsNan(ret_real))
166-
ret_real = 0.f;
167-
if (__spirv_IsNan(ret_imag))
168-
ret_imag = 0.f;
169-
return CMPLXF(ret_real, ret_imag);
160+
float e = __spirv_ocl_exp(z_real);
161+
return CMPLXF(e * __spirv_ocl_cos(z_imag), e * __spirv_ocl_sin(z_imag));
170162
}
171163

172164
DEVICE_EXTERN_C_INLINE

0 commit comments

Comments
 (0)