[Beignet] [PATCH v2] fix builtin function "fract"
Homer Hsing
homer.xing at intel.com
Wed Nov 6 22:55:23 PST 2013
v2: return nan for nan, +zero for +inf, -zero for -inf.
Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
backend/src/ocl_stdlib.tmpl.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h
index 154ea44..17b31e7 100644
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -1718,7 +1718,14 @@ INLINE_OVERLOADABLE float __gen_ocl_internal_fdim(float x, float y) {
return __gen_ocl_internal_fmax(x, y) - y;
}
#define BODY \
+ if (isnan(x)) { \
+ *p = x; \
+ return x; \
+ } \
*p = __gen_ocl_internal_floor(x); \
+ if (isinf(x)) { \
+ return x > 0 ? +0. : -0.; \
+ } \
return __gen_ocl_internal_fmin(x - *p, 0x1.FFFFFep-1F);
INLINE_OVERLOADABLE float fract(float x, global float *p) { BODY; }
INLINE_OVERLOADABLE float fract(float x, local float *p) { BODY; }
--
1.8.3.2
More information about the Beignet
mailing list