lib/rubystats/modules.rb
# Error function.
# Based on C-code for the error function developed at Sun Microsystems.
# Author:: Jaco van Kooten
Error function.
Based on C-code for the error function developed at Sun Microsystems.
Author:: Jaco van Kooten
Error function . Based on C - code for the error function developed at Sun Microsystems . Author :: Jaco van Kooten
def error(x)
      e_efx = 1.28379167095512586316e-01
      ePp = [ 1.28379167095512558561e-01,
        -3.25042107247001499370e-01,
        -2.84817495755985104766e-02,
        -5.77027029648944159157e-03,
        -2.37630166566501626084e-05 ]
      eQq = [ 3.97917223959155352819e-01,
        6.50222499887672944485e-02,
        5.08130628187576562776e-03,
        1.32494738004321644526e-04,
        -3.96022827877536812320e-06 ]
      ePa = [-2.36211856075265944077e-03,
        4.14856118683748331666e-01,
        -3.72207876035701323847e-01,
        3.18346619901161753674e-01,
        -1.10894694282396677476e-01,
        3.54783043256182359371e-02,
        -2.16637559486879084300e-03 ]
      eQa = [ 1.06420880400844228286e-01,
        5.40397917702171048937e-01,
        7.18286544141962662868e-02,
        1.26171219808761642112e-01,
        1.36370839120290507362e-02,
        1.19844998467991074170e-02 ]
      e_erx = 8.45062911510467529297e-01
      abs_x = (if x >= 0.0 then x else -x end)
      if abs_x < 0.84375
        if abs_x < 3.7252902984619141e-9 
          retval = abs_x + abs_x * e_efx
        else
          s = x * x
          p = ePp[0] + s * (ePp[1] + s * (ePp[2] + s * (ePp[3] + s * ePp[4])))
          q = 1.0 + s * (eQq[0] + s * (eQq[1] + s *
                                       ( eQq[2] + s * (eQq[3] + s * eQq[4]))))
          retval = abs_x + abs_x * (p / q)
        end
      elsif abs_x < 1.25
        s = abs_x - 1.0
        p = ePa[0] + s * (ePa[1] + s * 
                          (ePa[2] + s * (ePa[3] + s * 
           (ePa[4] + s * (ePa[5] + s * ePa[6])))))
        q = 1.0 + s * (eQa[0] + s * 
                       (eQa[1] + s * (eQa[2] + s * 
           (eQa[3] + s * (eQa[4] + s * eQa[5])))))
        retval = e_erx + p / q
      elsif abs_x >= 6.0
        retval = 1.0
      else
        retval = 1.0 - complementary_error(abs_x)
      end
      return (if x >= 0.0 then retval else -retval end)
    end
def error ( x ) e_efx = 1.28379167095512586316e-01 ePp = [ 1.28379167095512558561e-01 , - 3.25042107247001499370e-01 , - 2.84817495755985104766e-02 , - 5.77027029648944159157e-03 , - 2.37630166566501626084e-05 ] eQq = [ 3.97917223959155352819e-01 , 6.50222499887672944485e-02 , 5.08130628187576562776e-03 , 1.32494738004321644526e-04 , - 3.96022827877536812320e-06 ] ePa = [ - 2.36211856075265944077e-03 , 4.14856118683748331666e-01 , - 3.72207876035701323847e-01 , 3.18346619901161753674e-01 , - 1.10894694282396677476e-01 , 3.54783043256182359371e-02 , - 2.16637559486879084300e-03 ] eQa = [ 1.06420880400844228286e-01 , 5.40397917702171048937e-01 , 7.18286544141962662868e-02 , 1.26171219808761642112e-01 , 1.36370839120290507362e-02 , 1.19844998467991074170e-02 ] e_erx = 8.45062911510467529297e-01 abs_x = ( if x >= 0.0 then x else - x end ) if abs_x < 0.84375 if abs_x < 3.7252902984619141e-9 retval = abs_x + abs_x * e_efx else s = x * x p = ePp [ 0 ] + s * ( ePp [ 1 ] + s * ( ePp [ 2 ] + s * ( ePp [ 3 ] + s * ePp [ 4 ] ) ) ) q = 1.0 + s * ( eQq [ 0 ] + s * ( eQq [ 1 ] + s * ( eQq [ 2 ] + s * ( eQq [ 3 ] + s * eQq [ 4 ] ) ) ) ) retval = abs_x + abs_x * ( p / q ) end elsif abs_x < 1.25 s = abs_x - 1.0 p = ePa [ 0 ] + s * ( ePa [ 1 ] + s * ( ePa [ 2 ] + s * ( ePa [ 3 ] + s * ( ePa [ 4 ] + s * ( ePa [ 5 ] + s * ePa [ 6 ] ) ) ) ) ) q = 1.0 + s * ( eQa [ 0 ] + s * ( eQa [ 1 ] + s * ( eQa [ 2 ] + s * ( eQa [ 3 ] + s * ( eQa [ 4 ] + s * eQa [ 5 ] ) ) ) ) ) retval = e_erx + p / q elsif abs_x >= 6.0 retval = 1.0 else retval = 1.0 - complementary_error ( abs_x ) end return ( if x >= 0.0 then retval else - retval end ) end
Error function.
Error function .
# Coefficients for approximation to erf in [0.84375,1.25] # 0 < |x| < 0.84375 #|x| < 2**-28
x
<not_specific>