1. 15 8月, 2013 2 次提交
  2. 28 7月, 2013 1 次提交
  3. 19 5月, 2013 2 次提交
    • S
      math: add fma TODO comments about the underflow issue · 1e5eb735
      Szabolcs Nagy 提交于
      The underflow exception is not raised correctly in some
      cornercases (see previous fma commit), added comments
      with examples for fmaf, fmal and non-x86 fma.
      
      In fmaf store the result before returning so it has the
      correct precision when FLT_EVAL_METHOD!=0
      1e5eb735
    • S
      math: fix two fma issues (only affects non-nearest rounding mode, x86) · ffd8ac2d
      Szabolcs Nagy 提交于
      1) in downward rounding fma(1,1,-1) should be -0 but it was 0 with
      gcc, the code was correct but gcc does not support FENV_ACCESS ON
      so it used common subexpression elimination where it shouldn't have.
      now volatile memory access is used as a barrier after fesetround.
      
      2) in directed rounding modes there is no double rounding issue
      so the complicated adjustments done for nearest rounding mode are
      not needed. the only exception to this rule is raising the underflow
      flag: assume "small" is an exactly representible subnormal value in
      double precision and "verysmall" is a much smaller value so that
      	(long double)(small plus verysmall) == small
      then
      	(double)(small plus verysmall)
      raises underflow because the result is an inexact subnormal, but
      	(double)(long double)(small plus verysmall)
      does not because small is not a subnormal in long double precision
      and it is exact in double precision.
      now this problem is fixed by checking inexact using fenv when the
      result is subnormal
      ffd8ac2d
  4. 18 5月, 2013 2 次提交
    • S
      math: sin cos cleanup · bfda3793
      Szabolcs Nagy 提交于
      * use unsigned arithmetics
      * use unsigned to store arg reduction quotient (so n&3 is understood)
      * remove z=0.0 variables, use literal 0
      * raise underflow and inexact exceptions properly when x is small
      * fix spurious underflow in tanl
      bfda3793
    • S
      math: tan cleanups · 1d5ba3bb
      Szabolcs Nagy 提交于
      * use unsigned arithmetics on the representation
      * store arg reduction quotient in unsigned (so n%2 would work like n&1)
      * use different convention to pass the arg reduction bit to __tan
        (this argument used to be 1 for even and -1 for odd reduction
        which meant obscure bithacks, the new n&1 is cleaner)
      * raise inexact and underflow flags correctly for small x
        (tanl(x) may still raise spurious underflow for small but normal x)
        (this exception raising code increases codesize a bit, similar fixes
        are needed in many other places, it may worth investigating at some
        point if the inexact and underflow flags are worth raising correctly
        as this is not strictly required by the standard)
      * tanf manual reduction optimization is kept for now
      * tanl code path is cleaned up to follow similar logic to tan and tanf
      1d5ba3bb
  5. 16 5月, 2013 1 次提交
    • S
      math: use double_t for temporaries to avoid stores on i386 · e216951f
      Szabolcs Nagy 提交于
      When FLT_EVAL_METHOD!=0 (only i386 with x87 fp) the excess
      precision of an expression must be removed in an assignment.
      (gcc needs -fexcess-precision=standard or -std=c99 for this)
      
      This is done by extra load/store instructions which adds code
      bloat when lot of temporaries are used and it makes the result
      less precise in many cases.
      Using double_t and float_t avoids these issues on i386 and
      it makes no difference on other archs.
      
      For now only a few functions are modified where the excess
      precision is clearly beneficial (mostly polynomial evaluations
      with temporaries).
      
      object size differences on i386, gcc-4.8:
                   old   new
      __cosdf.o    123    95
      __cos.o      199   169
      __sindf.o    131    95
      __sin.o      225   203
      __tandf.o    207   151
      __tan.o      605   499
      erff.o      1470  1416
      erf.o       1703  1649
      j0f.o       1779  1745
      j0.o        2308  2274
      j1f.o       1602  1568
      j1.o        2286  2252
      tgamma.o    1431  1424
      math/*.o   64164 63635
      e216951f
  6. 08 1月, 2013 1 次提交
    • S
      math: erf and erfc cleanup · 121e3a38
      Szabolcs Nagy 提交于
      common part of erf and erfc was put in a separate function which
      saved some space and the new code is using unsigned arithmetics
      
      erfcf had a bug: for some inputs in [7.95,8] the result had
      more than 60ulp error: in expf(-z*z - 0.5625f) the argument
      must be exact but not enough lowbits of z were zeroed,
      -SET_FLOAT_WORD(z, ix&0xfffff000);
      +SET_FLOAT_WORD(z, ix&0xffffe000);
      fixed the issue
      121e3a38
  7. 02 1月, 2013 3 次提交
    • S
      math: bessel cleanup (jn.c and jnf.c) · 5652d700
      Szabolcs Nagy 提交于
      both jn and yn functions had integer overflow issues for large
      and small n
      
      to handle these issues nm1 (== |n|-1) is used instead of n and -n
      in the code and some loops are changed to make sure the iteration
      counter does not overflow
      
      (another solution could be to use larger integer type or even double
      but that has more size and runtime cost, on x87 loading int64_t or
      even uint32_t into an fpu register is more than two times slower than
      loading int32_t, and using double for n slows down iteration logic)
      
      yn(-1,0) now returns inf
      
      posix2008 specifies that on overflow and at +-0 all y0,y1,yn functions
      return -inf, this is not consistent with math when n<0 odd integer in yn
      (eg. when x->0, yn(-1,x)->inf, but historically yn(-1,0) seems to be
      special cased and returned -inf)
      
      some threshold values in jnf and ynf were fixed that seems to be
      incorrectly copy-pasted from the double version
      5652d700
    • S
      math: bessel cleanup (j1.c and j1f.c) · 5bb6b249
      Szabolcs Nagy 提交于
      a common code path in j1 and y1 was factored out so the resulting
      object code is a bit smaller
      
      unsigned int arithmetics is used for bit manipulation
      
      j1(-inf) now returns 0 instead of -0
      
      an incorrect threshold in the common code of j1f and y1f got fixed
      (this caused spurious overflow and underflow exceptions)
      
      the else branch in pone and pzero functions are fixed
      (so code analyzers dont warn about uninitialized values)
      5bb6b249
    • S
      math: bessel cleanup (j0.c and j0f.c) · 697acde6
      Szabolcs Nagy 提交于
      a common code path in j0 and y0 was factored out so the resulting
      object code is smaller
      
      unsigned int arithmetics is used for bit manipulation
      
      the logic of j0 got a bit simplified (x < 1 case was handled
      separately with a bit higher precision than now, but there are large
      errors in other domains anyway so that branch has been removed)
      
      some threshold values were adjusted in j0f and y0f
      697acde6
  8. 17 12月, 2012 7 次提交
    • S
      math: use 0x1p-120f and 0x1p120f for tiny and huge values · c6383b7b
      Szabolcs Nagy 提交于
      previously 0x1p-1000 and 0x1p1000 was used for raising inexact
      exception like x+tiny (when x is big) or x+huge (when x is small)
      
      the rational is that these float consts are large enough
      (0x1p-120 + 1 raises inexact even on ld128 which has 113 mant bits)
      and float consts maybe smaller or easier to load on some platforms
      (on i386 this reduced the object file size by 4bytes in some cases)
      c6383b7b
    • S
      math: tgammal.c fixes · d8a7619e
      Szabolcs Nagy 提交于
      this is not a full rewrite just fixes to the special case logic:
      +-0 and non-integer x<INT_MIN inputs incorrectly raised invalid
      exception and for +-0 the return value was wrong
      
      so integer test and odd/even test for negative inputs are changed
      and a useless overflow test was removed
      d8a7619e
    • S
      math: tanh.c cleanup similar to sinh, cosh · e42a977f
      Szabolcs Nagy 提交于
      comments are kept in the double version of the function
      
      compared to fdlibm/freebsd we partition the domain into one
      more part and select different threshold points:
      now the [log(5/3)/2,log(3)/2] and [log(3)/2,inf] domains
      should have <1.5ulp error
      (so only the last bit may be wrong, assuming good exp, expm1)
      
      (note that log(3)/2 and log(5/3)/2 are the points where tanh
      changes resolution: tanh(log(3)/2)=0.5, tanh(log(5/3)/2)=0.25)
      
      for some x < log(5/3)/2 (~=0.2554) the error can be >1.5ulp
      but it should be <2ulp
      (the freebsd code had some >2ulp errors in [0.255,1])
      
      even with the extra logic the new code produces smaller
      object files
      e42a977f
    • S
      math: sinh.c cleanup similar to the cosh one · f1434582
      Szabolcs Nagy 提交于
      comments are kept in the double version of the function
      f1434582
    • S
      math: finished cosh.c cleanup · 1aec620f
      Szabolcs Nagy 提交于
      changed the algorithm: large input is not special cased
      (when exp(-x) is small compared to exp(x))
      and the threshold values are reevaluated
      (fdlibm code had a log(2)/2 cutoff for which i could not find
      justification, log(2) seems to be a better threshold and this
      was verified empirically)
      
      the new code is simpler, makes smaller binaries and should be
      faster for common cases
      
      the old comments were removed as they are no longer true for the
      new algorithm and the fdlibm copyright was dropped as well
      because there is no common code or idea with the original anymore
      except for trivial ones.
      1aec620f
    • S
    • S
      525ad96e
  9. 15 12月, 2012 1 次提交
    • S
      math: fix i386/expl.s with more precise x*log2e · a8f73bb1
      Szabolcs Nagy 提交于
      with naive exp2l(x*log2e) the last 12bits of the result was incorrect
      for x with large absolute value
      
      with hi + lo = x*log2e is caluclated to 128 bits precision and then
        expl(x) = exp2l(hi) + exp2l(hi) * f2xm1(lo)
      this gives <1.5ulp measured error everywhere in nearest rounding mode
      a8f73bb1
  10. 12 12月, 2012 6 次提交
    • S
      math: add a non-dummy tgamma implementation · 0f53c1a4
      Szabolcs Nagy 提交于
      uses the lanczos approximation method with the usual tweaks.
      same parameters were selected as in boost and python.
      (avoides some extra work and special casing found in boost
      so the precision is not that good: measured error is <5ulp for
      positive x and <10ulp for negative)
      
      an alternative lgamma_r implementation is also given in the same
      file which is simpler and smaller than the current one, but less
      precise so it's ifdefed out for now.
      0f53c1a4
    • S
      math: cosh cleanup · 14cc9c7f
      Szabolcs Nagy 提交于
      do fabs by hand, don't check for nan and inf separately
      14cc9c7f
    • S
      math: fix comment in __rem_pio2f.c · 9c6b1de0
      Szabolcs Nagy 提交于
      9c6b1de0
    • S
      math: add empty __invtrigl.s to i386 and x86_64 · 1384ad5f
      Szabolcs Nagy 提交于
      __invtrigl is not needed when acosl, asinl, atanl have asm
      implementations
      1384ad5f
    • S
      math: clean up inverse trigonometric functions · b12a73d5
      Szabolcs Nagy 提交于
      modifications:
      * avoid unsigned->signed conversions
      * removed various volatile hacks
      * use FORCE_EVAL when evaluating only for side-effects
      * factor out R() rational approximation instead of manual inline
      * __invtrigl.h now only provides __invtrigl_R, __pio2_hi and __pio2_lo
      * use 2*pio2_hi, 2*pio2_lo instead of pi_hi, pi_lo
      
      otherwise the logic is not changed, long double versions will
      need a revisit when a genaral long double cleanup happens
      b12a73d5
    • S
      math: rewrite inverse hyperbolic functions to be simpler/smaller · 482ccd2f
      Szabolcs Nagy 提交于
      modifications:
      * avoid unsigned->signed integer conversion
      * do not handle special cases when they work correctly anyway
      * more strict threshold values (0x1p26 instead of 0x1p28 etc)
      * smaller code, cleaner branching logic
      * same precision as the old code:
          acosh(x) has up to 2ulp error in [1,1.125]
          asinh(x) has up to 1.6ulp error in [0.125,0.5], [-0.5,-0.125]
          atanh(x) has up to 1.7ulp error in [0.125,0.5], [-0.5,-0.125]
      482ccd2f
  11. 08 12月, 2012 1 次提交
  12. 18 11月, 2012 5 次提交
    • S
      math: use float constants in exp10f.c · a764db9a
      Szabolcs Nagy 提交于
      use the 'f' suffix when a float constant is not representable
      a764db9a
    • S
      math: expl.c cleanup · e93a0fe4
      Szabolcs Nagy 提交于
      raise overflow and underflow when necessary, fix various comments.
      e93a0fe4
    • S
      math: expf.c cleanup · ab1772c5
      Szabolcs Nagy 提交于
      similar to exp.c cleanup: use scalbnf, don't return excess precision,
      drop some optimizatoins.
      exp.c was changed to be more consistent with expf.c code.
      ab1772c5
    • S
      math: cleanup exp2.c exp2f.c and exp2l.c · 159c7655
      Szabolcs Nagy 提交于
      * old code relied on sign extension on right shift
      * exp2l ld64 wrapper was wrong
      * use scalbn instead of bithacks
      159c7655
    • S
      math: exp.c clean up · bbbf045c
      Szabolcs Nagy 提交于
      overflow and underflow was incorrect when the result was not stored.
      an optimization for the 0.5*ln2 < |x| < 1.5*ln2 domain was removed.
      did various cleanups around static constants and made the comments
      consistent with the code.
      bbbf045c
  13. 14 11月, 2012 2 次提交
  14. 13 11月, 2012 6 次提交