945 Commits

Author SHA1 Message Date
Rich Felker
aa1b4dff45 fix broken exponential asm
infinities were getting converted into nans. the new code simply tests
for infinity and replaces it with a large magnitude value of the same
sign.

also, the fcomi instruction is apparently not part of the i387
instruction set, so avoid using it.
2012-03-18 23:17:28 -04:00
Rich Felker
37eb14dd2b asm for lrint family on i386 2012-03-18 22:05:20 -04:00
nsz
dbdec9722e Merge branch 'master' of git://git.etalabs.net/musl 2012-03-19 02:55:31 +01:00
Rich Felker
6f26cf3dac asm exponential functions for i386 2012-03-18 21:43:43 -04: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
Rich Felker
b935147761 assembly optimizations for fmod/remainder functions 2012-03-18 17:09:34 -04:00
Rich Felker
8d9e948652 asm versions of some simple math functions for i386 and x86_64
these are functions that have direct fpu approaches to implementation
without problematic exception or rounding issues. x86_64 lacks
float/double versions because i'm unfamiliar with the necessary sse
code for performing these operations.
2012-03-18 16:43:54 -04: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
Rich Felker
9e2a895aaa fix loads of missing const in new libm, and some global vars (?!) in powl 2012-03-18 01:58:28 -04:00
Rich Felker
8e092217dd move nonstandard gamma() etc. to _GNU_SOURCE only
it's not even provided in the library at the moment, but could easily
be provided with weak aliases if desired.
2012-03-17 21:48:48 -04:00
Rich Felker
65db6bf5ea c++ seems to want some casts in the float representation-access macros 2012-03-17 21:40:10 -04:00
Rich Felker
da0acc32ef release notes for 0.8.7 v0.8.7 2012-03-17 20:35:25 -04:00
Rich Felker
b60053e762 try fixing/optimizing x86_64 fenv exception code
untested; may need followup-fixes.
2012-03-17 20:10:02 -04:00
Rich Felker
316e024f63 optimize x86 feclearexcept
if all exception flags will be cleared, we can avoid the expensive
store/reload of the environment and just use the fnclex instruction.
2012-03-17 19:29:00 -04:00
Rich Felker
9cb6878e74 fix x86_64 fe[gs]etround, analogous to nsz's x86 changes 2012-03-17 18:02:20 -04:00
Rich Felker
d5e576c752 minor 387 fenv optimizations 2012-03-17 17:49:10 -04:00
Rich Felker
0b337e04aa Merge remote branch 'nsz/master' 2012-03-17 17:34:30 -04: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
Rich Felker
523a3ab1a2 don't fail on inability to install dynamic linker (e.g. if not root) 2012-03-17 00:48:55 -04:00
Rich Felker
d3fc724759 one more fenv availability issue: lround 2012-03-17 00:02:36 -04:00
Rich Felker
2e77dc13f8 make fma and lrint functions build without full fenv support
this is necessary to support archs where fenv is incomplete or
unavailable (presently arm). fma, fmal, and the lrint family should
work perfectly fine with this change; fmaf is slightly broken with
respect to rounding as it depends on non-default rounding modes to do
its work.
2012-03-16 23:58:49 -04:00
Rich Felker
8c071f872b other side of the signgam namespace fix: use the internal name 2012-03-16 21:20:53 -04:00
Rich Felker
1a3dce4184 make signgam a weak alias for an internal symbol
otherwise, the standard C lgamma function will clobber a symbol in the
namespace reserved for the application.
2012-03-16 21:18:48 -04:00
Rich Felker
de7db6e927 fix namespace issues for lgamma, etc.
standard functions cannot depend on nonstandard symbols
2012-03-16 21:16:32 -04:00
Rich Felker
93a50a26cd Merge remote branch 'nsz/master' 2012-03-16 21:01:34 -04:00
Rich Felker
2cbb24bba3 remove junk sincos implementations in preparation to merge nsz's real ones 2012-03-16 20:53:05 -04:00
Rich Felker
a43c3a337f revert COPYRIGHT file changes in preparation to merge nsz's math branch 2012-03-16 20:52:00 -04:00
Rich Felker
6f21da618f update copyright status (math library and new year) 2012-03-16 19:18:00 -04:00
Rich Felker
9d507419db remove special nan handling from x86 sqrt asm
a double precision nan, when converted to extended (80-bit) precision,
will never end in 0x400, since the corresponding bits do not exist in
the original double precision value. thus there's no need to waste
time and code size on this check.
2012-03-15 19:56:36 -04:00
Rich Felker
1295848efb simplify nan check in sqrt (x86 asm); result of sqrt is never negative 2012-03-15 12:16:51 -04: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
Rich Felker
5657cc58e5 implement sincosf and sincosl functions; add prototypes
presumably broken gcc may generate calls to these, and it's said that
ffmpeg makes use of sincosf.
2012-03-15 02:38:42 -04:00
Rich Felker
46702f68f9 avoid changing NaNs in sqrt (x86 asm) to satisfy c99 f.9 recommendation 2012-03-15 01:55:54 -04:00
Rich Felker
809556e60a correctly rounded sqrt() asm for x86 (i387)
the fsqrt opcode is correctly rounded, but only in the fpu's selected
precision mode, which is 80-bit extended precision. to get a correctly
rounded double precision output, we check for the only corner cases
where two-step rounding could give different results than one-step
(extended-precision mantissa ending in 0x400) and adjust the mantissa
slightly in the opposite direction of the rounding which the fpu
already did (reported in the c1 flag of the fpu status word).

this should have near-zero cost in the non-corner cases and at worst
very low cost.

note that in order for sqrt() to get used when compiling with gcc, the
broken, non-conformant builtin sqrt must be disabled.
2012-03-15 01:29:03 -04:00
Rich Felker
e0a54e6725 correct rounding for i387 sqrtf function 2012-03-13 22:15:52 -04: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
Rich Felker
291f839a44 fix scanf handling of "0" (followed by immediate EOF) with "%x"
other cases with %x were probably broken too.

I would actually like to go ahead and replace this code in scanf with
calls to the new __intparse framework, but for now this calls for a
quick and unobtrusive fix without the risk of breaking other things.
2012-03-13 12:37:51 -04: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
Rich Felker
bf9d9dcaa6 implement nan, nanf, nanl 2012-03-13 01:55:25 -04:00
Rich Felker
b69f695ace first commit of the new libm!
thanks to the hard work of Szabolcs Nagy (nsz), identifying the best
(from correctness and license standpoint) implementations from freebsd
and openbsd and cleaning them up! musl should now fully support c99
float and long double math functions, and has near-complete complex
math support. tgmath should also work (fully on gcc-compatible
compilers, and mostly on any c99 compiler).

based largely on commit 0376d44a890fea261506f1fc63833e7a686dca19 from
nsz's libm git repo, with some additions (dummy versions of a few
missing long double complex functions, etc.) by me.

various cleanups still need to be made, including re-adding (if
they're correct) some asm functions that were dropped.
2012-03-13 01:17:53 -04:00
Rich Felker
d46cf2e14c add .gitignore file
I've had this around for a long time but somehow it never got
committed.
2012-03-09 03:39:28 -05:00
Rich Felker
405ce58dcf fix nan/infinity macros in math.h, etc.
the previous version not only failed to work in c++, but also failed
to produce constant expressions, making the macros useless as
initializers for objects of static storage duration.

gcc 3.3 and later have builtins for these, which sadly seem to be the
most "portable" solution. the alternative definitions produce
exceptions (for NAN) and compiler warnings (for INFINITY) on newer
versions of gcc.
2012-03-02 22:35:37 -05:00