[Beignet] [PATCH v2] libocl: fix degrees function precision issue.
xionghu.luo at intel.com
xionghu.luo at intel.com
Thu Aug 6 01:08:08 PDT 2015
From: Luo Xionghu <xionghu.luo at intel.com>
should define and use M_180_PI_F directly instead of using 180/M_PI_F.
v2: half degrees also need this.
Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
backend/src/libocl/include/ocl_float.h | 1 +
backend/src/libocl/tmpl/ocl_common.tmpl.cl | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/backend/src/libocl/include/ocl_float.h b/backend/src/libocl/include/ocl_float.h
index 916233b..e63eaf9 100644
--- a/backend/src/libocl/include/ocl_float.h
+++ b/backend/src/libocl/include/ocl_float.h
@@ -88,6 +88,7 @@ INLINE_OVERLOADABLE int __ocl_finitef (float x){
#define M_PI_4_F 0.7853981633974483F
#define M_1_PI_F 0.3183098861837907F
#define M_2_PI_F 0.6366197723675814F
+#define M_180_PI_F 57.295779513082321F
#define M_2_SQRTPI_F 1.1283791670955126F
#define M_SQRT2_F 1.4142135623730951F
#define M_SQRT1_2_F 0.7071067811865476F
diff --git a/backend/src/libocl/tmpl/ocl_common.tmpl.cl b/backend/src/libocl/tmpl/ocl_common.tmpl.cl
index 76aca2b..b6b09b5 100644
--- a/backend/src/libocl/tmpl/ocl_common.tmpl.cl
+++ b/backend/src/libocl/tmpl/ocl_common.tmpl.cl
@@ -44,7 +44,7 @@ OVERLOADABLE float clamp(float v, float l, float u) {
OVERLOADABLE float degrees(float radians) {
- return (180 / M_PI_F) * radians;
+ return M_180_PI_F * radians;
}
OVERLOADABLE float radians(float degrees) {
return (M_PI_F / 180) * degrees;
@@ -96,7 +96,7 @@ OVERLOADABLE half clamp(half v, half l, half u) {
return max(min(v, u), l);
}
OVERLOADABLE half degrees(half radians) {
- return ((half)(180 / M_PI_F)) * radians;
+ return ((half)(M_180_PI_F)) * radians;
}
OVERLOADABLE half radians(half degrees) {
return ((half)(M_PI_F / 180)) * degrees;
--
1.9.1
More information about the Beignet
mailing list