Improve the accuracy of built-in function asin.
authorYi Sun <yi.sun@intel.com>
Tue, 6 Aug 2013 14:02:49 +0000 (22:02 +0800)
committerZhigang Gong <zhigang.gong@linux.intel.com>
Wed, 7 Aug 2013 06:50:57 +0000 (14:50 +0800)
Method: asin(x) = x + (1 * x^3)/(2 * 3) + (1 * 3 * x^5)/(2*4 * 5) + \
(1 * 3 * 5 * x^7)/(2*4*6 * 7) + ...
Iterate this for 30 times.

Signed-off-by: Yi Sun <yi.sun@intel.com>
Reviewed-by: Homer Hsing <homer.xing@intel.com>
backend/src/ocl_stdlib.tmpl.h

index c9e54e2..69f84b0 100644 (file)
@@ -562,7 +562,16 @@ INLINE_OVERLOADABLE float __gen_ocl_internal_tanh(float x) {
   return (1 - y) / (1 + y);
 }
 INLINE_OVERLOADABLE float __gen_ocl_internal_asin(float x) {
-  return x + __gen_ocl_pow(x, 3) / 6 + __gen_ocl_pow(x, 5) * 3 / 40 + __gen_ocl_pow(x, 7) * 5 / 112;
+  float sum = x, c = x, m = 1.0;
+  int n = 1;
+  do
+  {
+    c *= (2 * n - 1) * x * x;
+    m *= (2 * n);
+    sum += ( c / m / (2 * n + 1));
+    n++;
+  }while( n < 30);
+  return sum;
 }
 INLINE_OVERLOADABLE float __gen_ocl_internal_asinpi(float x) {
   return __gen_ocl_internal_asin(x) / M_PI_F;