Commit Graph

513 Commits

Author SHA1 Message Date
Bruce Evans
50c8bd4e53 Oops, r336412 undid the fix of the overflow threshold in r323003. Restore
the previous overflow threshold and adjust comments.
2018-07-19 14:24:48 +00:00
Bruce Evans
1693fd03d9 Minor cleanups to csqrt*(), mostly in comments.
Remove the STDC CX_LIMITED_RANGE pragma and its verbose comment.  We still
don't have any C99 compilers (that support fenv pragmas), and if we did
then there are thousands of other places in libm that would need to use
them more than here.

The other cleanups are smaller.
2018-07-17 12:01:59 +00:00
Bruce Evans
9d7dc13615 Fix scaling bugs which gave innaccuracies and spurious underflows in csqrt()
and csqrtl().

When one component is huge and the other is tiny, scaling down the tiny
component gave spurious underflow.

When both components are denormal, not scaling them up gave inaccuracies
of 34+ ulps on not very carefully selected args.  Fixing this reduces the
maximum error to 1.6 ulps on the same set of args (mosly not denormal ones).

The scaling used multiplication of a complex variable by 2, but clang messes
this on amd64 up by losing the sign of -0.0.  Calculate the components
separately, as is well known to be needed for operations on more exceptional
values.
2018-07-17 10:44:16 +00:00
Bruce Evans
6f1b8a0792 Add a macro nan_mix() and use it to get NaN results that are (bitwise)
independent of the precision in most cases.  This is mainly to simplify
checking for errors.  r176266 did this for e_pow[f].c using a less
refined expression that often didn't work.  r176276 fixes an error in
the log message for r176266.  The main refinement is to always expand
to long double precision.  See old log messages (especially these 2)
and the comment on the macro for more general details.

Specific details:
- using nan_mix() consistently for the new and old pow*() functions was
  the only thing needed to make my consistency test for powl() vs pow()
  pass on amd64.

- catrig[fl].c already had all the refinements, but open-coded.

- e_atan2[fl].c, e_fmod[fl].c and s_remquo[fl] only had primitive NaN
  mixing.

- e_hypot[fl].c already had a different refined version of r176266.  Refine
  this further.  nan_mix() is not directly usable here since we want to
  clear the sign bit.

- e_remainder[f].c already had an earlier version of r176266.

- s_ccosh[f].c,/s_csinh[f].c already had a version equivalent to r176266.
  Refine this further.  nan_mix() is not directly usable here since the
  expression has to handle some non-NaN cases.

- s_csqrt.[fl]: the mixing was special and mostly wrong.  Partially fix the
  special version.

- s_ctanh[f].c already had a version of r176266.
2018-07-17 07:42:14 +00:00
Matt Macy
6813d08ff5 msun: add ld80/ld128 powl, cpow, cpowf, cpowl from openbsd
This corresponds to the latest status (hasn't changed in 9+
years) from openbsd of ld80/ld128 powl, and source cpowf, cpow,
cpowl (the complex power functions for float complex, double
complex, and long double complex) which are required for C99
compliance and were missing from FreeBSD. Also required for
some numerical codes using complex numbered Hamiltonians.

Thanks to jhb for tracking down the issue with making
weak_reference compile on powerpc.

When asked to review, bde said "I don't like it" - but
provided no actionable feedback or superior implementations.

Discussed with: jhb
Submitted by: jmd
Differential Revision: https://reviews.freebsd.org/D15919
2018-07-15 00:23:10 +00:00
Mark Johnston
7525d42f70 Reduce diff between msun/src/e_pow.c and msun/src/e_powf.c.
Remove unnecessary casts, use integer literal constants instead of
floating point constants where possible, and introduce three const
static variables to hold 0.5, 0.25, and 1/3.

PR:		229420
Submitted by:	Steve Kargl <sgk@troutmask.apl.washington.edu>
MFC after:	1 week
2018-07-08 16:33:58 +00:00
Mark Johnston
46a846f791 Fix whitespace issues in bessel function routines.
PR:		229423
Submitted by:	Steve Kargl <sgk@troutmask.apl.washington.edu>
MFC after:	3 days
2018-07-08 16:26:13 +00:00
Konstantin Belousov
0c0288a218 Add implementations for clog(3), clogf(3), and clog(3).
PR:	216863
Submitted by:	bde, Steven G. Kargl <sgk@troutmask.apl.washington.edu>
MFC after:	2 weeks
2018-05-13 09:54:34 +00:00
Eitan Adler
f5ce166436 msun: signed overflow in atan2
As a component of atan2(y, x), the case of x == 1.0 is farmed out to
atan(y). The current implementation of this comparison is vulnerable
to signed integer underflow (that is, undefined behavior), and it's
performed in a somewhat more complicated way than it need be. Change
it to not be quite so cute, rather directly comparing the high/low
bits of x to the specific IEEE-754 bit pattern that encodes 1.0.

Note that while there are three different e_atan* files in the
relevant directory, only this one needs fixing. e_atan2f.c already
compares against the full bit pattern encoding 1.0f, while
e_atan2l.cuses bitwise-ands/ors/nots and so doesn't require a change.

Closes #130

Submitted by:	Jeff Walden (@jswalden github PR #130)
Reviewed by:	bde
MFC After:	1 month
2018-02-14 07:59:30 +00:00
Eitan Adler
d52a982ea8 lib: Fix several typos and minor errors
- duplicate words
- typos
- references to old versions of FreeBSD

Reviewed by:	imp, benno
2017-12-27 03:23:41 +00:00
Ed Maste
a71393e7d3 lib/msun: remove trailing whitespace from e_pow.c
Submitted by:	Steve Kargl
MFC after:	1 week
2017-12-03 01:56:03 +00:00
Pedro F. Giffuni
5e53a4f90f lib: further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.
2017-11-26 02:00:33 +00:00
Ryan Libby
cf551d94ef lib/msun: avoid referring to broken LDBL_MAX
LDBL_MAX is broken on i386:
https://lists.freebsd.org/pipermail/freebsd-numerics/2012-September/000288.html

Gcc has produced +Infinity for LDBL_MAX on i386 and amd64 with -m32
for some time, and newer versions of gcc are now warning that the
"floating constant exceeds range of 'long double'".  Avoid this by
referring to proxy values instead.

Reviewed by:	bde
Approved by:	markj (mentor)
Sponsored by:	Dell EMC Isilon
2017-08-29 22:32:29 +00:00
Ryan Libby
4c889da8b6 Revert r322418, LDBL_MAX_EXP unsuitable for macro pasting on some arches
Either need a different way to spell HALF_LDBL_MAX, or a different way
to spell LDBL_MAX_EXP, or a different approach.

Reported by:	ian
2017-08-12 18:28:02 +00:00
Ryan Libby
9afac9fed9 lib/msun: avoid referring to broken LDBL_MAX
LDBL_MAX is broken on i386:
https://lists.freebsd.org/pipermail/freebsd-numerics/2012-September/000288.html

Gcc has produced +Infinity for LDBL_MAX on i386 and amd64 with -m32
for some time, and newer versions of gcc are now warning that the
"floating constant exceeds range of 'long double'".  Avoid this by
referring to half the value of LDBL_MAX instead.

Reviewed by:	bde
Approved by:	markj (mentor)
Sponsored by:	Dell EMC Isilon
2017-08-11 22:41:24 +00:00
Michal Meloun
e1b98d0774 Implement sincos, sincosf, and sincosl.
The primary benefit of these functions is that argument
reduction is done once instead of twice in independent
calls to sin() and cos().

* lib/msun/Makefile:
  . Add s_sincos[fl].c to the build.
  . Add sincos.3 documentation.
  . Add appropriate MLINKS.

* lib/msun/Symbol.map:
  . Expose sincos[fl] symbols in dynamic libm.so.

* lib/msun/man/sincos.3:
  . Documentation for sincos[fl].

* lib/msun/src/k_sincos.h:
  . Kernel for sincos() function.  This merges the individual kernels
    for sin() and cos().  The merger offered an opportunity to re-arrange
    the individual kernels for better performance.

* lib/msun/src/k_sincosf.h:
   . Kernel for sincosf() function.  This merges the individual kernels
     for sinf() and cosf(). The merger offered an opportunity to re-arrange
     the individual kernels for better performance.

* lib/msun/src/k_sincosl.h:
   . Kernel for sincosl() function.  This merges the individual kernels
     for sinl() and cosl(). The merger offered an opportunity to re-arrange
     the individual kernels for better performance.

* lib/msun/src/math.h:
  . Add prototytpes for sincos[fl]().

* lib/msun/src/math_private.h:
  . Add RETURNV macros.  This is needed to reset fpsetprec on I386
    hardware for a function with type void.

* lib/msun/src/s_sincos.c:
  . Implementation of sincos() where sin() and cos() were merged into
    one routine and possibly re-arranged for better performance.

* lib/msun/src/s_sincosf.c:
  . Implementation of sincosf() where sinf() and cosf() were merged into
    one routine and possibly re-arranged for better performance.

* lib/msun/src/s_sincosl.c:
  . Implementation of sincosl() where sinl() and cosl() were merged into
    one routine and possibly re-arranged for better performance.

PR:		215977, 218300
Submitted by:	Steven G. Kargl <sgk@troutmask.apl.washington.edu>
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D10765
2017-05-28 06:13:38 +00:00
Dimitry Andric
3a462c983d Silence a -Wunused warning about the junk variable being used to raise
an inexact floating point exception.  The variable cannot be eliminated,
unfortunately, otherwise the desired addition triggering the exception
will be emitted neither by clang, nor by gcc.

Reviewed by:	Steve Kargl, bde
MFC after:	3 days
2017-05-13 22:36:54 +00:00
Pedro F. Giffuni
6002d46737 msun: Remove trailing space in Sunsoft copyright statement.
Submittedby:	kargl
2017-04-23 22:31:12 +00:00
Mahdi Mokhtari
a287735349 Fix building of r313761 on platforms that
`long double` is alias of `double` (MIPS, etc)

PR:		216850 216851 216852 216856 216857 216858
Reported by:	emsate
Reviewed by:	bde emaste hselasky
Approved by:	bde emaste hselasky
Differential Revision:	https://reviews.freebsd.org/D9491
2017-02-17 08:22:32 +00:00
Mahdi Mokhtari
a11c507775 Add casinl() cacosl() catanl() casinhl() cacoshl() catanhl() APIs to msun
to improve C11 conformance.

PR:		216850 216851 216852 216856 216857 216858
Submitted by:	mmokhi
Reported by:	sgk@troutmask.apl.washington.edu
Reviewed by:	bde, mat, theraven
Approved by:	bde (src committer), mat (mentor)
Differential Revision:	https://reviews.freebsd.org/D9491
2017-02-15 07:59:54 +00:00
Ruslan Bukin
fae95359ee Don't use fmaxl/fminl on platforms with no long double support,
use fmax/fmin instead.

This fixes fmaxmin test failure on MIPS64.

Reviewed by:	emaste
Sponsored by:	DARPA, AFRL
Sponsored by:	HEIF5
Differential Revision:	https://reviews.freebsd.org/D8216
2016-10-11 20:31:59 +00:00
Ed Maste
a01a51a352 libm: remove unused variables
Sponsored by:	The FreeBSD Foundation
2016-10-05 17:04:58 +00:00
Ed Maste
cf825f93cc libm: remove unused variables for LDBL_MANT_DIG != 113
Sponsored by:	The FreeBSD Foundation
2016-09-30 20:20:07 +00:00
Ed Maste
dcdfa506cc libm: fix some unused variable (rcsid) and dangling else warnings
s_{fabs,fmax,logb,scalb}{,f,l}.c may be built elsewhere with a higher
WARNS setting.

Reviewed by:	ed
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D8061
2016-09-28 14:48:34 +00:00
Bruce Evans
a4c138885e Fix missing fmodl() on arches with 53-bit long doubles.
PR:		199422, 211965
MFC after:	1 week
2016-09-04 12:01:32 +00:00
Edward Tomasz Napierala
b8f41779a2 Fix frexpl() declaration to not include the field name.
MFC after:	1 month
2016-06-09 20:49:26 +00:00
Pedro F. Giffuni
75f46cf6c8 lib: minor spelling fixes in comments.
No functional change.
2016-05-01 19:37:33 +00:00
Dimitry Andric
a679d056de In libm's exp2(3), avoid left-shifting a negative integer, which is
undefined.  Replace it with the intended value, in a defined way.

Reviewed by:	bde
MFC after:	3 days
2015-08-09 10:00:13 +00:00
Tijl Coosemans
65c323f2ac Follow up to r284427: fix NaN mixing for ctanhf too. 2015-06-15 20:47:26 +00:00
Tijl Coosemans
68b433d790 - Change comments to be more consistent with s_ccosh.c and s_csinh.c.
- Fix a case where NaNs were not mixed correctly and signalling NaNs were
  not converted to quiet NaNs.
- Eliminate two negations from ctan(z).

In collaboration with:	bde
2015-06-15 20:40:44 +00:00
Tijl Coosemans
f0f050e0f9 Fix some exceptional cases where the sign of the result is unspecified
but must still satisfy csinh(conj(z)) == conj(csinh(z)) and csinh(-z) ==
-csinh(z).  This allows eliminating two negations from csin(z).

In collaboration with:	bde
2015-06-15 20:16:53 +00:00
Tijl Coosemans
db7548d040 Fix some exceptional cases where the sign of the result is unspecified
but must still satisfy ccosh(conj(z)) == conj(ccosh(z)) and ccosh(-z) ==
ccosh(z).

In collaboration with:	bde
2015-06-15 20:11:06 +00:00
Steve Kargl
5b3a5f8343 In r279493, the functions pzero[f](), qzero[f], pone[f](),
and qone[f]() were marked as __inline, but their forward
declarations were not updated.  Fix the forward declarations
to match the actual function declarations.

Requested by:	 bde
2015-05-17 16:27:06 +00:00
Steve Kargl
186f620727 According to POSIX.1-2008, the Bessel functions of second kind
should raise a divide-by-zero floating point exception for x = +-0
and an invalid floating point exception for x < 0 including x = -Inf.
Update the code to raise the exception and update the documentation
with hopefully better description of the behavior.

Reviewed by:	bde (code only)
2015-03-10 17:10:54 +00:00
Steve Kargl
a737ef56ab Give compilers a stronger hint to inline the functions
pzero[f], qzero[f], pone[f], and qone[f].  While here
fix the function declarations in accordance with style(9).
2015-03-01 20:32:47 +00:00
Steve Kargl
8192c85cb3 When j0() and j1() were converted to j0f() and j1f(), the threshold
values for the different invervals were not converted correctly.
Adjust the threshold values to values, which should agree with the
comments.

Reported by:	cognet (j1f only)
Discussed with: pfg, bde
Reviewed by:	bde
2015-03-01 20:26:03 +00:00
Pedro F. Giffuni
d300dc2302 msun: drop unnecessary checks (part 2).
Drop an unnecessary check in some calculations. The check
would have Coverity falsely conclude that a variable could
be left undefined.
2015-02-24 16:45:16 +00:00
Pedro F. Giffuni
8617260a03 msun: drop unnecessary checks.
Drop an unnecessary check in some calculations. The check
would have Coverity falsely conclude that variables could
be left undefined.

Discussed with:	kargl, bde
Reviewed by:	bde
2015-02-22 01:15:09 +00:00
Steve Kargl
dc98c00464 Truncate the exponent 'n' of type long to a domain contained
within [INT_MIN, INT_MAX] where the magnitude of the lower
and upper bounds are sufficiently large to span the range of
scalbn[fl].

While here, remove the GNU style bug in the function declarations.

Reviewed by:	bde, pfg
2015-02-07 00:38:18 +00:00
Pedro F. Giffuni
5b3ddf0928 scanblnl: drop extra braces.
Pointed out by:	bde
2015-02-03 16:16:52 +00:00
Pedro F. Giffuni
73c031c5d4 Reduce confusion in scalbnl() family of functions.
The changes unrelated to the bug in r277948 made
the code very difficult to understand to both
coverity and regular humans so take a step back
to something that is much easier to understand
for both and follows better the original code.

CID:	1267992, 1267993, 1267994
Discussed with:	kargl
2015-02-03 14:17:29 +00:00
Pedro F. Giffuni
311449a4e3 msun: use previously ignored value.
This fixes evaluation of exceptional values in scalblnl().
While here, simplify the code as suggested by Bruce Evans.

Reported by:	clang static analyzer
MFC after:	1 week
2015-01-30 19:19:03 +00:00
Ed Schouten
799cf446be Clarify to explain that C99 conforming compilers don't need CMPLX*().
Discussed with: kargl@
2014-12-24 10:13:53 +00:00
Ed Schouten
2cec876a59 Rename cpack*() to CMPLX*().
The C11 standard introduced a set of macros (CMPLX, CMPLXF, CMPLXL) that
can be used to construct complex numbers from a pair of real and
imaginary numbers. Unfortunately, they require some compiler support,
which is why we only define them for Clang and GCC>=4.7.

The cpack() function in libm performs the same task as CMPLX(), but
cannot be used to generate compile-time constants. This means that all
invocations of cpack() can safely be replaced by C11's CMPLX(). To keep
the code building with GCC 4.2, provide copies of CMPLX() that can at
least be used to generate run-time complex numbers.

This makes it easier to build some of the functions outside of libm.
2014-12-16 09:21:56 +00:00
Steve Kargl
5dc4735cb3 Adjust the |x| small limit from 0x1p-7 to 0x1p-9. This
adjustment increases the number of correctly rounded
cases within the interval on i386.

Requested by:	bde
2014-12-08 15:47:52 +00:00
Steve Kargl
2656e946c8 Update the constants associated with the evaluation of j0f(x)
for |x| small.

While here, remove the explicit cast of 0.25 to float.  Replace
a multiplication involving 0.25 by a division using an integer
constant 4.  Make a similar change in j0() to minimize the diff.

Suggested by:	bde
2014-12-05 19:00:55 +00:00
Steve Kargl
668986107d Fix a 20+ year bug by using an appropriate constant for
the transition from one asymptotic approximation to another
for the zeroth order Bessel and Neumann functions.

Reviewed by:	bde
2014-12-04 15:57:58 +00:00
Ed Maste
294246bb7d Revert r274772: it is not valid on MIPS
Reported by:	sbruno
2014-11-25 03:50:31 +00:00
Ed Maste
688fd61ae8 Use canonical __PIC__ flag
It is automatically set when -fPIC is passed to the compiler.

Reviewed by:	dim, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D1179
2014-11-21 02:05:48 +00:00
Steve Kargl
a4e4b355f4 The value small=2**-(p+3), where p is the precision, can be determine from
lgamma(x) = -log(x) - log(1+x) + x*(1-g) + x**2*P(x) with g = 0.57...
being the Euler constant and P(x) a polynomial.  Substitution of small
into the RHS shows that the last 3 terms are negligible in comparison to
the leading term.  The choice of 3 may be conservative.

The value large=2**(p+3) is detemined from Stirling's approximation
lgamma(x) = x*(log(x)-1) - log(x)/2 + log(2*pi)/2 + P(1/x)/x
Again, substitution of large into the RHS reveals the last 3 terms
are negligible in comparison to the leading term.

Move the x=+-0 special case into the |x|<small block.

In the ld80 and ld128 implementaion, use fdlibm compatible comparisons
involving ix, lx, and llx.  This replaces several floating point
comparisons (some involving fabsl()) and also fixes the special cases
x=1 and x=2.

While here
  . Remove unnecessary parentheses.
  . Fix/improve comments due to the above changes.
  . Fix nearby whitespace.

* src/e_lgamma_r.c:
  . Sort declaration.
  . Remove unneeded explicit cast for type conversion.
  . Replace a double literal constant by an integer literal constant.

* src/e_lgammaf_r.c:
  . Sort declaration.

* ld128/e_lgammal_r.c:
  . Replace a long double literal constant by a double literal constant.

* ld80/e_lgammal_r.c:
  . Remove unused '#include float.h'
  . Replace a long double literal constant by a double literal constant.

Requested by:	bde
2014-10-09 22:39:52 +00:00
Steve Kargl
3fbe079a34 Remove whitespace and 2 blank lines. 2014-10-02 23:08:36 +00:00
Steve Kargl
dde47d8bbc * Whitespace. 2014-09-25 22:15:10 +00:00
Steve Kargl
f382031d34 For targets that have a signed zero, lgamma_r(-0, &signgamp) should
set signgamp = -1.

Submitted by:	enh at google dot com (e_lgamma[f]_r.c)
2014-09-17 19:01:22 +00:00
Steve Kargl
f7efd14df1 * Makefile:
. Hook e_lgammal[_r].c to the build.
  . Create man page links for lgammal[-r].3.

* Symbol.map:
  . Sort lgammal to its rightful place.
  . Add FBSD_1.4 section for the new lgamal_r symbol.

* ld128/e_lgammal_r.c:
  . 128-bit implementataion of lgammal_r().

* ld80/e_lgammal_r.c:
  . Intel 80-bit format implementation of lgammal_r().

* src/e_lgamma.c:
  . Expose lgammal as a weak reference to lgamma for platforms
    where long double is mapped to double.

* src/e_lgamma_r.c:
  . Use integer literal constants instead of real literal constants.
    Let compiler(s) do the job of conversion to the appropriate type.
  . Expose lgammal_r as a weak reference to lgamma_r for platforms
    where long double is mapped to double.

* src/e_lgammaf_r.c:
  . Fixed the Cygnus Support conversion of e_lgamma_r.c to float.
    This includes the generation of new polynomial and rational
    approximations with fewer terms.  For each approximation, include
    a comment on an estimate of the accuracy over the relevant domain.
  . Use integer literal constants instead of real literal constants.
    Let compiler(s) do the job of conversion to the appropriate type.
    This allows the removal of several explicit casts of double values
    to float.

* src/e_lgammal.c:
  . Wrapper for lgammal() about lgammal_r().

* src/imprecise.c:
  . Remove the lgamma.

* src/math.h:
  . Add a prototype for lgammal_r().

* man/lgamma.3:
  . Document the new functions.

Reviewed by:	bde
2014-09-15 23:21:57 +00:00
Steve Kargl
e85326216f Remove an initialized, but otherwise, unused variable. 2014-09-04 23:50:05 +00:00
Steve Kargl
733331540a According to the ISO C standard, lgamma(-integer) returns
inf and raises the divided-by-zero exception.  Compilers
constant fold one/zero to inf but do not raise the exception.
Introduce a volatile vzero to prevent the constant folding.

Move the declaration of zero into the main declaration block.

While here, fix a nearby disordering of 'lx,ix'

Discussed with:	bde
2014-09-01 18:57:13 +00:00
Steve Kargl
e63062b5bf Fix a tab that somehow became 8 spaces.
Remove parentheses in a return statement to be consistent with the
rest of the file.

Rename sin_pi() in the float version to sin_pif().

Remove large comment that precedes sin_pif().  The comment
duplicates a comment in e_lgamma_r.c where the algorithm
is documented.

Requested by:	bde
2014-09-01 16:24:25 +00:00
Steve Kargl
795b92049d Compute sin(pi*x) without actually doing the pi*x multiplication.
sin_pi(x) is only called for x < 0 and |x| < 2**(p-1) where p is
the precision of x.  The new argument reduction is an optimization
compared to the old code, and it removes a chunk of dead code.
Accuracy tests in the intervals (-21,-20), (-20,-19), ... (-1,0)
show no differences between the old and new code.

Obtained from:	bde
2014-08-31 21:38:03 +00:00
Steve Kargl
53c7f22849 Fix the order of "const volatile" to be consistent with
the rest of msun.
2014-08-30 17:31:53 +00:00
Steve Kargl
79c2e69a3f Make tiny volatile to prevent the compiler(s) from
constant folding expressions of the form "1 - tiny",
which are used to raise FE_INEXACT.
2014-08-30 17:14:47 +00:00
Steve Kargl
55ad7cd740 When r255294 was committed, it exposed the symbols lgammal, powl,
and tgammal in libm.  These functions are part of ISO/IEC 9899:1999
and their prototypes should have been moved into the appropriate
__ISO_C_VISIBLE >= 1999 section.  After moving the prototypes,
remnants of r236148 can be removed.

PR:		standards/191754
Reviewed by:	bde
2014-08-09 15:53:40 +00:00
Steve Kargl
d781108453 * Update the comments to agree with commit r226595.
* While here, fix a nearby typo in a comment.
2014-07-13 23:10:39 +00:00
Steve Kargl
3b5e0d0f96 * Makefile:
. Add s_erfl.c to building libm.
  . Add MLINKS for erfl.3 and erfcl.3.

* Symbol.map:
  . Move erfl and erfcl to their proper location.

* ld128/s_erfl.c:
  . Implementations of erfl and erfcl in the IEEE 754 128-bit format.

* ld80/s_erfl.c:
  . Implementations of erfl and erfcl in the Intel 80-bit format.

* man/erf.3:
  . Document the new functions.
  . While here, remove an incomplete sentence.

* src/imprecise.c:
  . Remove the stupidity of mapping erfl and erfcl to erf and erfc.

* src/math.h:
  . Move the declarations of erfl and erfcl to their proper place.

* src/s_erf.c:
  . For architectures where double and long double are the same
    floating point format, use weak references to map erfl to
    erf and ercl to erfc.

Reviewed by:	bde (many earlier versions)
2014-07-13 17:05:03 +00:00
Steve Kargl
7e1c60ae94 * Use 9 digits instead of 11 digits in efx and efx8.
* Update the domain and range of comments for the polynomial
  approximations, including using the the correct variable names
  (e.g., pp(x) instead of p(x)).

* Use hex values of the form 0x3e0375d4 instead of 0x1.06eba8p-3,
  which was obtained from printf("%.6a").

* In the domain [0.84375, 1.25], qa(x) can be reduced from a 4th
  order polynomial to 3rd order.

* In the domain [1.25,1/0.35], sa(x) can be reduced from a 4th
  order polynomial to 3rd order.

* In the domain [1/0.35, 11], the 4th order polynomials rb(x) and
  sb(x) can be reduced to 2nd and 3rd order, respectively.
2014-07-13 16:24:16 +00:00
Steve Kargl
c9cb48ff4d * Update the comments that refer to erf[c](nan) and erf[c](+-inf)
to use erf[c]f.
2014-07-13 16:05:33 +00:00
Steve Kargl
019ffb5df8 * Use the volatile qualifier for 'tiny' to prevent compilers
from erronously constant folding expressions of the form
  '1 - tiny'.  This allows erf[f](x) to raise INEXACT.

* Use 0.5, 1, and 2, which are exactly representable in radix-2
  floating point formats.  This reduces diffs between s_erf[fl].c.

* While here, add a comment about efx and efx8.
2014-07-13 15:45:45 +00:00
Steve Kargl
f2c0cd942c Whitespace. 2014-07-13 15:15:51 +00:00
Marcel Moolenaar
e7d939bda2 Remove ia64.
This includes:
o   All directories named *ia64*
o   All files named *ia64*
o   All ia64-specific code guarded by __ia64__
o   All ia64-specific makefile logic
o   Mention of ia64 in comments and documentation

This excludes:
o   Everything under contrib/
o   Everything under crypto/
o   sys/xen/interface
o   sys/sys/elf_common.h

Discussed at: BSDcan
2014-07-07 00:27:09 +00:00
Andrew Turner
cd82739201 Use __fenv_static for all static inline functions. 2014-01-25 16:03:08 +00:00
Steve Kargl
1531aa5f6a * msun/man/cosh.3:
* msun/man/sinh.3:
* msun/man/tanh.3:
  . Fix grammar.

* msun/src/e_coshl.c:
* msun/src/e_sinhl.c:
  . Fix comment.

* msun/src/s_tanhl.c:
  . Remove unused variables.
  . Fix location/indentation of comments.
  . Use comparison involving ints instead of long double.
  . Re-order polynomial evaluation on ld128 for |x| < 0.25.
    For now, retain the older order in an "#if 0 ... #else" block.
  . Use int comparison to short-circuit the |x| < 1.5 condition.

Requested by:	bde
2013-12-31 23:59:33 +00:00
Steve Kargl
a48e1f224c * Makefile:
. Hook coshl, sinhl, and tanhl into libm.
  . Create symbolic links for corresponding manpages.
  . While here remove a nearby extraneous space.

* Symbol.map:
* src/math.h:
  . Move coshl, sinhl, and tanhl to their proper locations.

* man/cosh.3:
* man/sinh.3:
* man/tanh.3:
  . Update the manpages.

* src/e_cosh.c:
* src/e_sinh.c:
* src/s_tanh.c:
  . Add weak reference for LBDL_MANT_DIG==53 targets.

* src/imprecise.c:
  . Remove the coshl, sinhl, and tanhl kludge.

* src/e_coshl.c:
  . ld80 and ld128 implementation of coshl().

* src/e_sinhl.c:
  . ld80 and ld128 implementation of sinhl().

* src/s_tanhl.c:
  . ld80 and ld128 implementation of tanhl().

Obtained from:	bde (mostly), das and kargl
2013-12-30 01:06:21 +00:00
Steve Kargl
30a919dde7 Yet, another attempt to fix the libm breakage due to the
changes in s_roundl.c to use bit twiddling.

Reported by:	ian
2013-11-07 22:46:13 +00:00
Steve Kargl
0e9dcedc67 Fix bulding libm on platforms with LDBL_MANT_DIG == 53.
Reported by:	ian
2013-11-07 21:20:34 +00:00
Steve Kargl
db89cf8efb * Use "math.h" instead of <math.h>.
* Use bit twiddling.  This requires inclusion of math_private.h
  and inclusion of float.h in s_roundl.c.  Raise invalid exception.
* Use literal integer constants where possible.  Let the compiler
  do the appropriate conversion.
* In s_roundf.c, use an F suffix on float constants instead of
  promoting float to double and then converting the result back
  to float. In s_roundl.c, use an L suffix.
* In s_roundl.c, use the ENTERI and RETURNI macros.  This requires
  the inclusion of fpmath.h and on __i386__ class hardware ieeefp.h.

Reviewed by:	bde
2013-11-06 23:44:52 +00:00
Andrew Turner
0a10f22a30 On ARM EABI double precision floating point values are stored in the
endian the CPU is in, i.e. little-endian on most ARM cores.

This allows ARMv4 and ARMv5 boards to boot with the ARM EABI.
2013-09-07 14:04:10 +00:00
David Chisnall
4758b87596 Add stub implementations of the missing C++11 math functions.
These are weak and so can be replaced by other versions in applications
that choose to do so, and will give a linker warning when used so that
applications that rely on the extra precision can avoid them.

Note that since the C/C++ specs only guarantee that long double has
precision equal to double, code that actually relies on these functions
having greater precision is unportable at best and broken at worst.
2013-09-06 07:58:23 +00:00
Steve Kargl
e826e6be2b * Whitespace. 2013-08-28 16:59:55 +00:00
Steve Kargl
2a3910b931 * s_erf.c:
. Use integer literal constants instead of double literal constants.

* s_erff.c:
  . Use integer literal constants instead of casting double literal
    constants to float.
  . Update the threshold values from those carried over from erf() to
    values appropriate for float.
  . New sets of polynomial coefficients for the rational approximations.
    These coefficients have little, but positive, effect on the maximum
    error in ULP in the four intervals, but do improve the overall
    speed of execution.
  . Remove redundant GET_FLOAT_WORD(ix,x) as hx already contained the
    contents that is packed into ix.
  . Update the mask that is used to zero-out lower-order bits in x in
    the intervals [1.25, 2.857143] and [2.857143, 12].  In tests on
    amd64, this change improves the maximum error in ULP from 6.27739
    and 63.8095 to 3.16774 and 2.92095 on these intervals for erffc().

Reviewed by:	bde
2013-08-27 19:46:56 +00:00
David Chisnall
fb69d6083d Restore the longer form of the _Generic. The short form does not work in C++. 2013-07-29 12:33:03 +00:00
David Chisnall
6b69e627a8 Reenable the isnan(double) / isinf(double) declarations when targeting C89 + SUSv2 mode. 2013-07-29 08:32:13 +00:00
David Chisnall
b8f19c9247 Cleaner support for type qualifiers.
Submitted by:	Pasi Parviainen
2013-07-13 13:04:38 +00:00
David Chisnall
e21be487d3 Ensure that the _Generic() macro in math.h works with qualified types.
tgmath.h contains the same bugs and so should be fixed in the same way.
2013-07-13 10:10:45 +00:00
David Chisnall
1583bcb4ee Fix the build with C++ where __builtin_types_compatible_p is not allowed. 2013-07-12 11:03:51 +00:00
David Chisnall
95f82796a9 Fix some typoes in math.h cleanup. 2013-07-11 19:34:16 +00:00
David Chisnall
a3fc79de87 Cleanups to math.h that prevent namespace conflicts with C++.
Reviewed by:	bde
MFC after:	3 days
2013-07-11 17:41:04 +00:00
Eitan Adler
19eb5fb06b Make the order of operations for lib/msun more clear.
Tested with md5 sum of object code

Reported by:	swildner@DragonFlyBSD.org
Submitted by:	bde
2013-06-24 19:12:17 +00:00
David Schultz
998b640bcb Add implementations of acoshl(), asinhl(), and atanhl(). This is a
merge of the work done by bde and myself.
2013-06-10 06:04:58 +00:00
David Schultz
0b8d0b5be9 Style fixes.
Submitted by:	bde
2013-06-05 05:33:01 +00:00
Steve Kargl
3ffff4bad5 ld80 and ld128 implementations of expm1l(). This code started life
as a fairly faithful implementation of the algorithm found in

PTP Tang, "Table-driven implementation of the Expm1 function
in IEEE floating-point arithmetic," ACM Trans. Math. Soft., 18,
211-222 (1992).

Over the last 18-24 months, the code has under gone significant
optimization and testing.

Reviewed by:	bde
Obtained from:	bde (most of the optimizations)
2013-06-03 19:51:32 +00:00
David Schultz
25a4d6bfda Add logl, log2l, log10l, and log1pl.
Submitted by:	bde
2013-06-03 09:14:31 +00:00
David Schultz
e4afa19c33 I'm happy to finally commit stephen@'s implementations of cacos,
cacosh, casin, casinh, catan, and catanh. Thanks to stephen@ and bde@
for working on these.

Submitted by:	stephen@
Reviewed by:	bde
2013-05-30 04:49:26 +00:00
David Schultz
7dbbb6dde3 Fix some regressions caused by the switch from gcc to clang. The fixes
are workarounds for various symptoms of the problem described in clang
bugs 3929, 8100, 8241, 10409, and 12958.

The regression tests did their job: they failed, someone brought it
up on the mailing lists, and then the issue got ignored for 6 months.
Oops. There may still be some regressions for functions we don't have
test coverage for yet.
2013-05-27 08:50:10 +00:00
Dimitry Andric
0779690c2e Only define isnan, isnanf, __isnan and __isnanf in libc.so, not in
libc.a and libc_p.a.  In addition, define isnan in libm.a and libm_p.a,
but not in libm.so.

This makes it possible to statically link executables using both isnan
and isnanf with libc and libm.

Tested by:	kargl
MFC after:	1 week
2012-11-10 21:22:10 +00:00
Kevin Lo
0f5e7edc14 Fix typo; s/ouput/output 2012-11-07 07:00:59 +00:00
Warner Losh
98fd12e162 Revert r241756 2012-10-22 13:21:11 +00:00
Warner Losh
b3f94d242f Revert r241755 2012-10-22 13:20:31 +00:00
Warner Losh
527a7c56f7 Document the method used to compute expf. Taken from exp, with
changes to reflect differences in computation between the two.
2012-10-19 22:47:44 +00:00
Warner Losh
aa616aa22d Document the methods used to compute logf. Taken and edited from the
double version, with adaptations for the differences between it and
the float version.
2012-10-19 22:46:48 +00:00
Steve Kargl
a077586c53 * src/math_private.h:
. Change the API for the LD80C by removing the explicit passing
    of the sign bit.  The sign can be determined from the last
    parameter of the macro.
  . On i386, load long double by bit manipulations to work around
    at least a gcc compiler issue.  On non-i386 ld80 architectures,
    use a simple assignment.

* ld80/s_expl.c:
  . Update the only consumer of LD80C.

Submitted by:	bde
Approved by:	das (mentor)
2012-09-29 16:40:12 +00:00
Steve Kargl
340076f0f6 * Use ENTERI() and RETURNI() to toggle the rounding precision if
necessary, so that cosl(), sinl() and tanl() work on i386 even
  for naive callers.

Suggested by:	bde
Reviewed by:	bde
Approved by: 	das (mentor)
2012-09-22 15:38:29 +00:00