Commit Graph
84 Commits
Author SHA1 Message Date
Szabolcs Nagy a764db9a08 math: use float constants in exp10f.c
use the 'f' suffix when a float constant is not representable
2012-11-18 03:52:29 +01:00
Szabolcs Nagy e93a0fe49d math: expl.c cleanup
raise overflow and underflow when necessary, fix various comments.
2012-11-18 03:49:16 +01:00
Szabolcs Nagy ab1772c597 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.
2012-11-18 03:42:09 +01:00
Szabolcs Nagy 159c7655d0 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
2012-11-17 23:39:39 +01:00
Szabolcs Nagy bbbf045ce9 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.
2012-11-17 23:22:41 +01:00
Szabolcs Nagy 68847ecd3a fenv: return FE_TONEAREST in dummy fegetround 2012-11-14 09:27:54 +01:00
Szabolcs Nagy 45ff9d8eb6 math: ld80 invtrig cleanups
keeping only commonly used data in invtrigl
2012-11-14 01:01:38 +01:00
Szabolcs Nagy 529a8de46c math: simplify hypot and hypotf using scalbn
this also fixes overflow/underflow raising and excess
precision issues (as those are handled well in scalbn)
2012-11-13 21:54:32 +01:00
Szabolcs Nagy 6d3f1a39c1 math: turn off the STRICT_ASSIGN workaround by default
the volatile hack in STRICT_ASSIGN is only needed if
assignment is not respected and excess precision is kept.
gcc -fexcess-precision=standard and -ffloat-store both
respect assignment and musl use these flags by default.
i kept the macro for now so the workaround may be used
for bad compilers in the future.
2012-11-13 19:59:02 +01:00
Szabolcs Nagy 033a9d6ad2 math: use '#pragma STDC FENV_ACCESS ON' when fenv is accessed 2012-11-13 13:34:45 +01:00
Szabolcs Nagy c4359e0130 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)
2012-11-13 10:55:35 +01:00
Szabolcs Nagy 666271c105 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)
2012-11-13 10:30:40 +01:00
Szabolcs Nagy 662ed20065 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)
2012-11-13 10:12:07 +01:00
Szabolcs Nagy cfbaba79a2 complex: add C11 CMPLX macros and replace cpack with them 2012-11-13 01:31:49 +01:00
Szabolcs Nagy e2fe959fe2 math: raise flags in logl.c on <= 0 arguments 2012-11-13 00:49:55 +01:00
Szabolcs Nagy 52bcf3f5fb math: fix logb*.c exceptions now that ilogb raises invalid 2012-11-13 00:45:51 +01:00
Szabolcs Nagy 37aa7f7301 math: raise flags in log2l.c on <= 0 arguments, and fix volatile 2012-11-13 00:30:06 +01:00
Szabolcs Nagy 04ccbdca6d math: raise exception flags in log1pl.c on <= -1 arguments 2012-11-13 00:21:09 +01:00
Szabolcs Nagy be81f51030 math: raise invalid flag in ilogb*.c on +-0, +-inf and nan 2012-11-12 23:58:18 +01:00
Szabolcs Nagy 6f64505df3 math: fix exception behaviour of expm1l.c on inf and nan 2012-11-12 23:41:48 +01:00
Szabolcs Nagy b03c19a4b9 math: fix long double constants in exp10l.c 2012-11-12 23:13:28 +01:00
nsz 2d321fa062 complex: make _Complex_I work with gcc -std=c99 -pedantic-errors 2012-10-21 02:31:04 +02:00
nsz 23e6940a2c math: fix _BSD_SOURCE namespace in math.h 2012-08-13 22:06:01 +02:00
nsz 1fb0169154 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
2012-08-08 20:18:16 +02:00
nsz e5fb6820a4 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.
2012-06-20 23:25:58 +02:00
nsz b1cf11c090 math: fix nextafter definition in tgmath.h 2012-05-28 22:55:03 +02:00
nsz 6255c4c6a5 search: add comments to tsearch_avl.c 2012-05-13 01:50:53 +02:00
nsz d197d6421c search: add tdestroy (gnu extension) 2012-05-13 01:34:20 +02:00
nsz 3738a96e05 math: fix remquo.c when x==-y and a subnormal remainder bug as well
backported fix from freebsd:
http://svnweb.FreeBSD.org/base?view=revision&revision=233973
2012-05-08 00:22:56 +02:00
nsz 6ab8136b44 add FORCE_EVAL macro to evaluate float expr for their side effect
updated nextafter* to use FORCE_EVAL, it can be used in many other
places in the math code to improve readability.
2012-05-06 21:24:28 +02:00
nsz 6cf865dba6 math: nextafter and nexttoward cleanup
make nexttoward, nexttowardf independent of long double representation.
fix nextafterl: it did not raise underflow flag when the result was 0.
2012-05-06 13:08:59 +02:00
nsz f697d66b81 math: change the formula used for acos.s
old: 2*atan2(sqrt(1-x),sqrt(1+x))
new: atan2(fabs(sqrt((1-x)*(1+x))),x)
improvements:
* all edge cases are fixed (sign of zero in downward rounding)
* a bit faster (here a single call is about 131ns vs 162ns)
* a bit more precise (at most 1ulp error on 1M uniform random
samples in [0,1), the old formula gave some 2ulp errors as well)
2012-05-05 01:11:56 +02:00
nsz 37eaec3ad3 math: fix x86 asin accuracy
use (1-x)*(1+x) instead of (1-x*x) in asin.s
the later can be inaccurate with upward rounding when x is close to 1
2012-04-04 17:34:28 +02:00
nsz 7eabe8e690 math: minor cleanups in ceil and floor 2012-03-29 14:09:57 +02:00
nsz d79ac8c38f math: remove x86 modf asm
the int part was wrong when -1 < x <= -0 (+0.0 instead of -0.0)
and the size and performace gain of the asm version was negligible
2012-03-29 14:05:16 +02:00
nsz f6ceccd922 math: rewrite modf.c and clean up modff.c
cleaner implementation with unions and unsigned arithmetic
2012-03-29 14:03:18 +02:00
nsz 9f58d06007 math: fix modfl.c bug
modfl(+-inf) was wrong on ld80 because the explicit msb
was not taken into account during inf vs nan check
2012-03-28 23:51:09 +02:00
nsz cf682072ce math: fix a regression in powl and do some cleanups
previously a division was accidentally turned into integer div
(w = -i/NXT;) instead of long double div (w = -i; w /= NXT;)
2012-03-27 22:49:37 +02:00
nsz bbfbc7edaf math: add dummy tgamma and tgammaf implementations 2012-03-27 22:17:36 +02:00
nsz 1b229a2098 math: remove comment about aliasing lgamma as gamma
It is probably not worth supporting gamma.
(it was already deprecated in 4.3BSD)
2012-03-27 22:12:20 +02:00
nsz ad23771c32 math: fix typo in i386 remquof and remquol asm
(fldl instruction was used instead of flds and fldt)
2012-03-27 22:01:21 +02:00
nsz e68a4633e0 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-26 13:47:31 +02:00
nsz c5ec5b2ce9 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-23 11:16:56 +01:00
nsz 6d8df2b972 minor rintl.c fix: remove unsupported ldbl format message 2012-03-23 01:26:04 +01:00
nsz cb8fce4b4f fix tgammal: don't set the signgam global
(tgamma must be thread-safe, signgam is for lgamma* functions)
2012-03-23 01:18:12 +01:00
nsz a4a0c91275 acos.s fix: use the formula acos(x) = atan2(sqrt(1-x),sqrt(1+x))
the old formula atan2(1,sqrt((1+x)/(1-x))) was faster but
could give nan result at x=1 when the rounding mode is
FE_DOWNWARD (so 1-1 == -0 and 2/-0 == -inf), the new formula
gives -0 at x=+-1 with downward rounding.
2012-03-22 14:54:47 +01:00
nsz 91c28f61f4 nearbyint optimization (only clear inexact when necessary)
old code saved/restored the fenv (the new code is only as slow
as that when inexact is not set before the call, but some other
flag is set and the rounding is inexact, which is rare)

before:
bench_nearbyint_exact              5000000 N        261 ns/op
bench_nearbyint_inexact_set        5000000 N        262 ns/op
bench_nearbyint_inexact_unset      5000000 N        261 ns/op

after:
bench_nearbyint_exact             10000000 N         94.99 ns/op
bench_nearbyint_inexact_set       25000000 N         65.81 ns/op
bench_nearbyint_inexact_unset     10000000 N         94.97 ns/op
2012-03-20 22:49:19 +01:00
nsz 8c6fc860a9 remove a fixme comment 2012-03-20 20:08:35 +01:00
nsz f1347a3a45 clean up pow.c and powf.c
fix comments about special cases
2012-03-20 20:04:53 +01:00
nsz 615bbd365f clean up powl.c
fix special cases, use multiplication instead of scalbnl
2012-03-20 19:59:50 +01:00
nsz 1e2fea632b fix a cbrtl.c regression and remove x87 precision setting 2012-03-20 15:17:15 +01:00
nsz 03c52e137a Merge branch 'master' of git://git.etalabs.net/musl 2012-03-20 10:25:02 +01:00
nsz c879a9592f Merge branch 'master' of git://git.etalabs.net/musl 2012-03-20 04:09:14 +01:00
nsz 0b0735af45 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-20 03:13:26 +01:00
nsz 634c3a6302 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 23:55:06 +01:00
nsz 0cbb654791 code cleanup of named constants
zero, one, two, half are replaced by const literals
The policy was to use the f suffix for float consts (1.0f),
but don't use suffix for long double consts (these consts
can be exactly represented as double).
2012-03-19 23:41:19 +01:00
nsz b03255af77 fix remainder*.c: remove useless long double cast 2012-03-19 23:39:47 +01:00
nsz 4caa17b2a1 don't try to create non-standard denormalization signal
Underflow exception is only raised when the result is
invalid, but fmod is always exact. x87 has a denormalization
exception, but that's nonstandard. And the superflous *1.0
will be optimized away by any compiler that does not honor
signaling nans.
2012-03-19 23:30:45 +01:00
nsz 75483499da new modff.c code, fix nan handling in modfl 2012-03-19 23:27:45 +01:00
nsz 2786c7d216 use scalbn or *2.0 instead of ldexp, fix fmal
Some code assumed ldexp(x, 1) is faster than 2.0*x,
but ldexp is a wrapper around scalbn which uses
multiplications inside, so this optimization is
wrong.

This commit also fixes fmal which accidentally
used ldexp instead of ldexpl loosing precision.

There are various additional changes from the
work-in-progress const cleanups.
2012-03-19 22:57:58 +01:00
nsz 01fdfd491b fix long double const workaround in cbrtl 2012-03-19 22:49:03 +01:00
nsz 2e8c8fbe7d don't inline __rem_pio2l so the code size is smaller 2012-03-19 19:26:31 +01:00
nsz c3587effe2 minor fix in __tanl (get sign properly) 2012-03-19 19:14:32 +01:00
nsz eca1c35e5b remove long double const workarounds
Some long double consts were stored in two doubles as a workaround
for x86_64 and i386 with the following comment:
/* Long double constants are slow on these arches, and broken on i386. */
This is most likely old gcc bug related to the default x87 fpu
precision setting (it's double instead of double extended on BSD).
2012-03-19 18:52:17 +01:00
nsz 9a810cb685 fix erfl wrapper for long double==double case 2012-03-19 18:06:06 +01:00
nsz 8051e08e10 simplify scalbn*.c implementations
The old scalbn.c was wrong and slow, the new one is just slow.
(scalbn(0x1p+1023,-2097) should give 0x1p-1074, but the old code gave 0)
2012-03-19 10:54:07 +01:00
nsz f767aba8af Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 10:50:42 +01:00
nsz 9322344fa4 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 10:20:24 +01:00
nsz 0627e58af8 Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 08:01:21 +01:00
nsz dbdec9722e Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 02:55:31 +01:00
nsz 682e471400 remove unnecessary TODO comments from fma.c 2012-03-19 02:05:57 +01:00
nsz d09a83f613 fmal bug fix: nan input should not raise exception 2012-03-19 00:59:16 +01:00
nsz b1cbd70743 add fma implementation for x86
correctly rounded double precision fma using extended
precision arithmetics for ld80 systems (x87)
2012-03-19 00:36:55 +01:00
nsz afad262440 simplify lround and llround functions
Simple wrappers around round is enough because
spurious inexact exception is allowed.
2012-03-18 20:52:33 +01:00
nsz 65db00983f make lrint and llrint functions work without fenv support 2012-03-18 20:40:43 +01:00
nsz 9b6899f2c5 faster lrint and llrint functions
A faster workaround for spurious inexact exceptions
when the result cannot be represented. The old code
actually could be wrong, because gcc reordered the
integer conversion and the exception check.
2012-03-18 19:27:39 +01:00
nsz 88cfaf8a14 fix i386 fegetround and make fesetround faster
Note that the new fesetround has slightly different semantics:

Storing the floating-point environment with fnstenv makes the
next fldenv (or fldcw) "non-signaling", so unmasked and pending
exceptions does not invoke the exception handler.
(These are rare since exceptions are handled immediately and by
default all exceptions are masked anyway. But if one manually
unmasks an exception in the control word then either sets the
corresponding exception flag in the status word or the execution
of an exception raising floating-point operation gets interrupted
then it may happen).
So the old implementation did not trap in some rare cases
where the new implementation traps.

However POSIX does not specify anything like the x87 exception
handling traps and the fnstenv/fldenv pair is significantly slower
than the fnstcw/fldcw pair (new code is about 5x faster here and
it's dominated by the function call overhead).
2012-03-17 13:46:15 +01:00
nsz 40305f74bd in math.h make lgamma_r and non-double bessel _GNU_SOURCE only
long double and float bessel functions are no longer xsi extensions
2012-03-15 09:29:53 +01:00
nsz 0144b45b71 efficient sincos based on sin and cos 2012-03-15 08:17:28 +01:00
nsz 32ca5ef3ff math cleanup: use 1.0f instead of 1.0F 2012-03-13 21:11:46 +01:00
nsz 8d0a6f7a1c math cleanup: use 1.0f instead of (float)1.0 2012-03-13 20:24:23 +01:00
nsz 9560b6b152 remove libm.h includes when math.h and float.h are enough 2012-03-13 19:51:14 +01:00
nsz df8b3e5aef clean up __expo2.c, use a slightly better k constant 2012-03-13 16:38:22 +01:00
nsz 3a6c828652 fix copyright notice for the math lib 2012-03-13 16:06:43 +01:00