[libclc] [libclc] Move sign to the CLC builtins library (PR #115699)
Fraser Cormack via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 25 02:56:12 PST 2024
================
@@ -0,0 +1,38 @@
+#include <clc/clcmacro.h>
+#include <clc/internal/clc.h>
+#include <clc/relational/clc_isnan.h>
+
+#define CLC_SIGN(TYPE, F) \
+ _CLC_DEF _CLC_OVERLOAD TYPE __clc_sign(TYPE x) { \
+ if (__clc_isnan(x)) { \
+ return 0.0F; \
+ } \
+ if (x > 0.0F) { \
+ return 1.0F; \
+ } \
+ if (x < 0.0F) { \
+ return -1.0F; \
+ } \
+ return x; /* -0.0 or +0.0 */ \
----------------
frasercrmck wrote:
True, my mistake. Forgetting the NaNs, though, my first sentence holds: `copysign(0.0, x < 0.0)` doesn't return `1.0` if `x > 0` nor `-1.0` if `x < 0` as OpenCL's `sign` is required to. I'm assuming you're saying `float sign(float x) { return copysign(0.0, x < 0); }` is a correct implementation of `sign`.
https://github.com/llvm/llvm-project/pull/115699
More information about the cfe-commits
mailing list