| Commit message (Expand) | Author | Age | Files | Lines |
| * | add missing erfcl wrapper for archs where long double is plain double | Rich Felker | 2013-07-28 | 1 | -0/+4 |
| * | math: add fma TODO comments about the underflow issue•••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
| Szabolcs Nagy | 2013-05-19 | 3 | -2/+14 |
| * | math: fix two fma issues (only affects non-nearest rounding mode, x86)•••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
| Szabolcs Nagy | 2013-05-19 | 1 | -4/+38 |
| * | math: sin cos cleanup•••* 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
| Szabolcs Nagy | 2013-05-18 | 10 | -112/+128 |
| * | math: tan cleanups•••* 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
| Szabolcs Nagy | 2013-05-18 | 6 | -106/+80 |
| * | math: use double_t for temporaries to avoid stores on i386•••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
| Szabolcs Nagy | 2013-05-15 | 21 | -28/+31 |
| * | math: erf and erfc cleanup•••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
| Szabolcs Nagy | 2013-01-07 | 3 | -297/+207 |
| * | math: bessel cleanup (jn.c and jnf.c)•••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
| Szabolcs Nagy | 2013-01-01 | 2 | -164/+161 |
| * | math: bessel cleanup (j1.c and j1f.c)•••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)
| Szabolcs Nagy | 2013-01-01 | 2 | -187/+138 |
| * | math: bessel cleanup (j0.c and j0f.c)•••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
| Szabolcs Nagy | 2013-01-01 | 2 | -203/+161 |
| * | math: use 0x1p-120f and 0x1p120f for tiny and huge values•••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)
| Szabolcs Nagy | 2012-12-16 | 10 | -27/+27 |
| * | math: tgammal.c fixes•••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
| Szabolcs Nagy | 2012-12-16 | 1 | -28/+23 |
| * | math: tanh.c cleanup similar to sinh, cosh•••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
| Szabolcs Nagy | 2012-12-16 | 3 | -173/+83 |
| * | math: sinh.c cleanup similar to the cosh one•••comments are kept in the double version of the function
| Szabolcs Nagy | 2012-12-16 | 3 | -170/+71 |
| * | math: finished cosh.c cleanup•••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.
| Szabolcs Nagy | 2012-12-16 | 3 | -142/+49 |
| * | math: x86_64 version of expl, fixed some comments in the i386 version | Szabolcs Nagy | 2012-12-16 | 4 | -4/+112 |
| * | math: move x86_64 exp2l implementation to exp2l.s from expl.s | Szabolcs Nagy | 2012-12-16 | 3 | -85/+76 |
| * | math: fix i386/expl.s with more precise x*log2e•••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
| Szabolcs Nagy | 2012-12-14 | 2 | -7/+107 |
| * | math: add a non-dummy tgamma implementation•••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.
| Szabolcs Nagy | 2012-12-12 | 2 | -20/+215 |
| * | math: cosh cleanup•••do fabs by hand, don't check for nan and inf separately
| Szabolcs Nagy | 2012-12-12 | 3 | -70/+63 |
| * | math: fix comment in __rem_pio2f.c | Szabolcs Nagy | 2012-12-12 | 1 | -2/+2 |
| * | math: add empty __invtrigl.s to i386 and x86_64•••__invtrigl is not needed when acosl, asinl, atanl have asm
implementations
| Szabolcs Nagy | 2012-12-12 | 2 | -0/+0 |
| * | math: clean up inverse trigonometric functions•••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
| Szabolcs Nagy | 2012-12-11 | 12 | -377/+258 |
| * | math: rewrite inverse hyperbolic functions to be simpler/smaller•••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]
| Szabolcs Nagy | 2012-12-11 | 9 | -406/+149 |
| * | fix trailing whitespace issues that crept in here and there | Rich Felker | 2012-12-07 | 1 | -1/+1 |
| * | math: use float constants in exp10f.c•••use the 'f' suffix when a float constant is not representable
| Szabolcs Nagy | 2012-11-18 | 1 | -1/+1 |
| * | math: expl.c cleanup•••raise overflow and underflow when necessary, fix various comments.
| Szabolcs Nagy | 2012-11-18 | 1 | -24/+19 |
| * | math: expf.c cleanup•••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.
| Szabolcs Nagy | 2012-11-18 | 2 | -63/+55 |
| * | math: cleanup exp2.c exp2f.c and exp2l.c•••* old code relied on sign extension on right shift
* exp2l ld64 wrapper was wrong
* use scalbn instead of bithacks
| Szabolcs Nagy | 2012-11-17 | 3 | -86/+56 |
| * | math: exp.c clean up•••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.
| Szabolcs Nagy | 2012-11-17 | 1 | -72/+49 |
| * | math: ld80 invtrig cleanups•••keeping only commonly used data in invtrigl
| Szabolcs Nagy | 2012-11-14 | 8 | -110/+87 |
| * | math: simplify hypot and hypotf using scalbn•••this also fixes overflow/underflow raising and excess
precision issues (as those are handled well in scalbn)
| Szabolcs Nagy | 2012-11-13 | 2 | -11/+4 |
| * | math: use '#pragma STDC FENV_ACCESS ON' when fenv is accessed | Szabolcs Nagy | 2012-11-13 | 9 | -0/+10 |
| * | math: excess precision fix modf, modff, scalbn, scalbnf•••old code was correct only if the result was stored (without the
excess precision) or musl was compiled with -ffloat-store.
now we use STRICT_ASSIGN to work around the issue.
(see note 160 in c11 section 6.8.6.4)
| Szabolcs Nagy | 2012-11-13 | 4 | -22/+18 |
| * | math: fix scalbn and scalbnf on overflow/underflow•••old code was correct only if the result was stored (without the
excess precision) or musl was compiled with -ffloat-store.
(see note 160 in n1570.pdf section 6.8.6.4)
| Szabolcs Nagy | 2012-11-13 | 2 | -10/+24 |
| * | math: fix nextafter and nexttoward on maxdbl and maxflt input•••old code (return x+x;) returns correct value and raises correct
flags only if the result is stored as double (or float)
| Szabolcs Nagy | 2012-11-13 | 4 | -4/+4 |
| * | math: raise flags in logl.c on <= 0 arguments | Szabolcs Nagy | 2012-11-13 | 2 | -9/+3 |
| * | math: fix logb*.c exceptions now that ilogb raises invalid | Szabolcs Nagy | 2012-11-13 | 3 | -25/+17 |
| * | math: raise flags in log2l.c on <= 0 arguments, and fix volatile | Szabolcs Nagy | 2012-11-13 | 1 | -8/+3 |
| * | math: raise exception flags in log1pl.c on <= -1 arguments | Szabolcs Nagy | 2012-11-13 | 1 | -7/+2 |
| * | math: raise invalid flag in ilogb*.c on +-0, +-inf and nan | Szabolcs Nagy | 2012-11-12 | 3 | -6/+18 |
| * | math: fix exception behaviour of expm1l.c on inf and nan | Szabolcs Nagy | 2012-11-12 | 1 | -13/+7 |
| * | math: fix long double constants in exp10l.c | Szabolcs Nagy | 2012-11-12 | 1 | -2/+2 |
| * | Merge remote-tracking branch 'nsz/exp' | Rich Felker | 2012-08-13 | 2 | -40/+35 |
| |\ |
|
| | * | math: fix exp.s on i386 and x86_64 so the exception flags are correct•••exp(inf), exp(-inf), exp(nan) used to raise wrong flags
| nsz | 2012-08-08 | 2 | -40/+35 |
| * | | remove significandl•••this function never existed historically; since the float/double
functions it's based on are nonstandard and deprecated, there's really
no justification for its existence except that glibc has it. it can be
added back if there's ever really a need...
| Rich Felker | 2012-08-13 | 1 | -7/+0 |
| * | | add significand[fl] math functions | Rich Felker | 2012-08-13 | 3 | -0/+21 |
| |/ |
|
| * | fix missing prototype and simplify sincosl on ld64 archs | Rich Felker | 2012-07-02 | 1 | -4/+2 |
| * | fix invalid implicit pointer conversion in ld64 modfl | Rich Felker | 2012-07-02 | 1 | -1/+1 |
| * | math: fix fma bug on x86 (found by Bruno Haible with gnulib)•••The long double adjustment was wrong:
The usual check is
mant_bits & 0x7ff == 0x400
before doing a mant_bits++ or mant_bits-- adjustment since
this is the only case when rounding an inexact ld80 into
double can go wrong. (only in nearest rounding mode)
After such a check the ++ and -- is ok (the mantissa will end
in 0x401 or 0x3ff).
fma is a bit different (we need to add 3 numbers with correct
rounding: hi_xy + lo_xy + z so we should survive two roundings
at different places without precision loss)
The adjustment in fma only checks for zero low bits
mant_bits & 0x3ff == 0
this way the adjusted value is correct when rounded to
double or *less* precision.
(this is an important piece in the fma puzzle)
Unfortunately in this case the -- is not a correct adjustment
because mant_bits might underflow so further checks are needed
and this was the source of the bug.
| nsz | 2012-06-20 | 1 | -2/+10 |