Exemple #1
0
 static inline A0_n kernel_atan(const A0_n a0_n)
 {
   typedef typename meta::scalar_of<A0>::type sA0;
   const A0 tan3pio8  = double_constant<A0, 0x4003504f333f9de6ll>();
   const A0 tanpio8 = double_constant<A0, 0x3fda827999fcef31ll>();
   const A0 a0 = {a0_n};
   const A0 x =  nt2::abs(a0);
   const bA0 flag1 = lt(x,  tan3pio8);             
   const bA0 flag2 = logical_and(ge(x, tanpio8), flag1); 
   A0 yy = if_zero_else(flag1, Pio_2<A0>());
   yy = select(flag2, Pio_4<A0>(), yy);
   A0 xx = select(flag1, x, -rec(x));
   xx = select(flag2, minusone(x)/oneplus(x),xx);
   A0 z = sqr(xx);
   z = z*horner< NT2_HORNER_COEFF_T(sA0, 5,
                                (0xbfec007fa1f72594ll,
                                 0xc03028545b6b807all,
                                 0xc052c08c36880273ll,
                                 0xc05eb8bf2d05ba25ll,
                                 0xc0503669fd28ec8ell)
                                )>(z)/
       horner< NT2_HORNER_COEFF_T(sA0, 6,
                                (0x3ff0000000000000ll,
                                 0x4038dbc45b14603cll,
                                 0x4064a0dd43b8fa25ll,
                                 0x407b0e18d2e2be3bll,
                                 0x407e563f13b049eall,
                                 0x4068519efbbd62ecll)
                                )>(z);
   z = fma(xx, z, xx);
   const A0 morebits = double_constant<A0, 0x3c91a62633145c07ll>();
   z = seladd(flag2, z, mul(Half<A0>(), morebits));
   z = z+if_zero_else(flag1, morebits);
   return yy + z;
 }
Exemple #2
0
 static inline A0_n asin(const A0_n a0_n)
 {
   const A0 a0 = { a0_n };
   A0 sign, x;
   x = nt2::abs(a0);
   sign = bitofsign(a0);
   const bA0 x_smaller_1e_4 = lt(x, single_constant<A0, 0x38d1b717>()); //1.0e-4f;
   const bA0 x_larger_05    = gt(x, Half<A0>());
   const bA0 x_else         = logical_or(x_smaller_1e_4, x_larger_05);
   A0 a = if_else_zero(x_smaller_1e_4, x);
   const A0 b = if_else_zero(x_larger_05, Half<A0>()*oneminus(x));
   A0 z = b_or(b_or(if_zero_else(x_else, sqr(x)), a), b);
   x = if_zero_else(x_else, x);
   a = if_else_zero(x_larger_05, sqrt(z));
   x = b_or(a, x);
   A0 z1 = madd(z,  single_constant<A0, 0x3d2cb352>(), single_constant<A0, 0x3cc617e3>());
   z1 = madd(z1, z, single_constant<A0, 0x3d3a3ec7>());
   z1 = madd(z1, z, single_constant<A0, 0x3d9980f6>());
   z1 = madd(z1, z, single_constant<A0, 0x3e2aaae4>());
   z1 = madd(z1, z*x, x);
   z = select(x_smaller_1e_4, z, z1);
   z1 = z+z;
   z1 = Pio_2<A0>()-z1;
   z = select(x_larger_05, z1, z);
   return b_xor(z, sign);
 }
Exemple #3
0
 template < class AA0 > static inline AA0 branch2(const AA0 & a0)
 {
   typedef typename meta::scalar_of<AA0>::type sAA0; 
   AA0 q = rec(a0);
   AA0 w = sqrt(q); 
   AA0 p3 = w *
   horner< NT2_HORNER_COEFF_T(sAA0, 8,
                      (0xbd8c100e, 
                       0x3e3ef887, 
                       0xbe5ba616, 
                       0x3df54214, 
                       0xbb69539e, 
                       0xbd4b8bc1, 
                       0xb6612dc2, 
                       0x3f4c422a
                       ) ) > (q);
   w = sqr(q);
   AA0 xn =  q*
   horner< NT2_HORNER_COEFF_T(sAA0, 8,
                      (0x4201aee0, 
                       0xc2113945, 
                       0x418c7f6a, 
                       0xc09f3306, 
                       0x3f8040aa, 
                       0xbe46a57f, 
                       0x3d84ed6e, 
                       0xbdffff97
                       ) ) > (w)-Pio_4<AA0>();
   return if_zero_else(eq(a0, Inf<AA0>()), p3*nt2::sin(xn+a0)); 
 }
Exemple #4
0
   template < class AA0 > static inline AA0 branch2(const AA0 & x)
   {
  typedef typename meta::scalar_of<AA0>::type stype; 
  AA0 q = rec(x);
  AA0 w = sqrt(q);
  AA0 p3 = w *
    horner< NT2_HORNER_COEFF_T(stype, 8,
                      (0x3d8d98f9,
                       0xbe69f6b3,
                       0x3ea0ad85,
                       0xbe574699,
                       0x3bb21b25,
                       0x3e18ec50,
                       0x36a6f7c5,
                       0x3f4c4229
                       ) ) > (q);
  w = sqr(q);
  AA0 xn =  q*
    horner< NT2_HORNER_COEFF_T(stype, 8,
                      (0xc233e16d,
                       0x424af04a,
                       0xc1c6dca7,
                       0x40e72299,
                       0xbfc5bd69,
                       0x3eb364d9,
                       0xbe27bad7,
                       0x3ebfffdd
                       ) ) > (w)-single_constant<AA0,0x4016cbe4 > ();
    return if_zero_else(eq(x, Inf<AA0>()), p3*cos(xn+x));
 }
Exemple #5
0
        static inline A0_n kernel_atan(const A0_n a0_n)
        {
          const A0 a0 = {a0_n};
          const A0 x = nt2::abs(a0);

          //here x is positive
          const bA0 flag1 = lt(x, single_constant<A0, 0x401a827a>()); //tan3pio8);
          const bA0 flag2 = logical_and(ge(x, single_constant<A0, 0x3ed413cd>()), flag1);
          A0 yy =  if_zero_else(flag1, Pio_2<A0>());
          yy =  select(flag2, Pio_4<A0>(), yy);
          A0 xx =   select(flag1, x, -rec(x));
          xx =  select(flag2, (minusone(x)/oneplus(x)),xx);
          const A0 z = sqr(xx);
          A0 z1 = madd(z,  single_constant<A0, 0x3da4f0d1>(),single_constant<A0, 0xbe0e1b85>());
          const A0 z2 = madd(z,  single_constant<A0, 0x3e4c925f>(),single_constant<A0, 0xbeaaaa2a>());
          z1 = madd(z1, sqr(z), z2);
          return  add(yy, madd(xx, mul( z1, z), xx));
        }
Exemple #6
0
 BOOST_FORCEINLINE static void conf_bounds(const A0& a0, A1& a1,
                                           const value_type& alpha )
 {
   typedef nt2::memory::container<tag::table_, value_type, nt2::_2D>  semantic;
   NT2_AS_TERMINAL_IN(semantic, pcov, boost::proto::child_c<3>(a0));
   const In0& x  = boost::proto::child_c<0>(a0);
   const In1& mu = boost::proto::child_c<1>(a0);
   const In2& sigma = boost::proto::child_c<2>(a0);
   auto z = (log(if_zero_else(is_lez(x), x))-mu)/sigma;
   // this is [1, x0]*pcov*[1; x0]
   auto zvar = fma(fma(pcov(2,2), z, Two<value_type>()*pcov(1,2)), z, pcov(1,1));
   BOOST_ASSERT_MSG(nt2::globalall(nt2::is_gez(zvar)), "Covariance matrix must be positive");
   value_type normz = -nt2::norminv(alpha*nt2::Half<value_type>());
   auto halfwidth =  normz*nt2::sqrt(zvar)/sigma;
   boost::proto::child_c<0>(a1) = Half<value_type>()*nt2::erfc(-Sqrt_2o_2<value_type>()*z);
   boost::proto::child_c<1>(a1) = Half<value_type>()*nt2::erfc(-Sqrt_2o_2<value_type>()*(z-halfwidth));
   boost::proto::child_c<2>(a1) = Half<value_type>()*nt2::erfc(-Sqrt_2o_2<value_type>()*(z+halfwidth));
 }