History log of /freebsd-current/lib/msun/src/math.h
Revision Date Author Comments
# 22ddb5bb 12-Apr-2024 Collin Funk <collin.funk1@gmail.com>

math: Add long double constant definitions

These constants are GNU libc extensions that are likely to be adopted
by the next POSIX revision [1]. The definitions can be verified in
a PARI-GP shell session:

* M_El: exp (1)
* M_LOG2El: log (exp (1)) / log (2)
* M_LOG10El: log (exp (1)) / log (10)
* M_LN2l: log (2)
* M_LN10l: log (10)
* M_PIl: Pi
* M_PI_2l: Pi / 2
* M_PI_4l: Pi / 4
* M_1_PIl: 1 / Pi
* M_2_PIl: 2 / Pi
* M_2_SQRTPIl: 2 / sqrt (Pi)
* M_SQRT2l: sqrt (2)
* M_SQRT1_2l: 1 / sqrt (2)

[1] https://austingroupbugs.net/view.php?id=828

Put these behind __BSD_VISIBLE || __XSI_VISIBLE >= 800 to future-proof
these changes. They shouldn't be defined at lower levels of XSI, but don't
have other XSI 800 stuff in place yet.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
Reviewed by: imp, allanjude
Pull Request: https://github.com/freebsd/freebsd-src/pull/1121


# 4309f9f2 12-Sep-2023 Martin Oliveira <martin.oliveira@eideticom.com>

include/math.h: fix warning with -Wconversion

The way the __fp_type_select macro uses the _Generic expression causes
gcc to throw a warning on valid code if the -Wconversion flag is used.

For example, consider the following program:

#include <math.h>
int main()
{
double x = 1.0;
isnan(x);
return 0;
}

which throws a warning:

$ gcc -Wconversion a.c
a.c:5:15: warning: conversion from 'double' to 'float' may change value [-Wfloat-conversion]
5 | isnan(x);
| ^

This happens because the functions are invoked inside of the _Generic.
Looking at the example of _Generic in the C11 specification, one sees
that the parameters are outside of the _Generic expression (see page 79
here: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf).

Reference: https://stackoverflow.com/a/68309379
Signed-off-by: Martin Oliveira <martin.oliveira@eideticom.com>
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/841


# 0dd5a560 28-Jan-2024 Steve Kargl <kargl@FreeBSD.org>

lib/msun: Cleanup after $FreeBSD$ removal

Remove no longer needed explicit inclusion of sys/cdefs.h.

PR: 276669
MFC after: 1 week


# dc36d6f9 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

lib: Remove ancient SCCS tags.

Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by: Netflix


# 1b681154 19-Nov-2023 Warner Losh <imp@FreeBSD.org>

math: Move to const instead of __const

There's no reason to use the __const construct here. This is a left-over
from supporting K&R and ANSI compilers in the original Sun msun. All
other K&R crutches have been removed. Remove these as well. There's no
semantic difference. And there's already several others in math.h.

Sponsored by: Netflix


# 42b38843 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .h pattern

Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/


# e50027e3 14-Jul-2022 Dimitry Andric <dim@FreeBSD.org>

Remove unnecessary const and volatile qualifiers from __fp_type_select()

Since https://github.com/llvm/llvm-project/commit/ca75ac5f04f2, clang 15
has a new warning about _Generic selection expressions, such as used in
math.h:

lib/libc/gdtoa/_ldtoa.c:82:10: error: due to lvalue conversion of the controlling expression, association of type 'volatile float' will never be selected because it is qualified [-Werror,-Wunreachable-code-generic-assoc]
switch (fpclassify(u.e)) {
^
lib/msun/src/math.h:109:2: note: expanded from macro 'fpclassify'
__fp_type_select(x, __fpclassifyf, __fpclassifyd, __fpclassifyl)
^
lib/msun/src/math.h:85:14: note: expanded from macro '__fp_type_select'
volatile float: f(x), \
^

This is because the controlling expression always undergoes lvalue
conversion first, dropping any cv-qualifiers. The 'const', 'volatile',
and 'volatile const' associations will therefore never be used.

MFC after: 1 week
Reviewed by: theraven
Differential Revision: https://reviews.freebsd.org/D35815


# dce5f3ab 25-Oct-2021 Steve Kargl <kargl@FreeBSD.org>

[LIBM] implementations of sinpi[fl], cospi[fl], and tanpi[fl]

Both IEEE-754 2008 and ISO/IEC TS 18661-4 define the half-cycle
trignometric functions cospi, sinpi, and tanpi. The attached
patch implements cospi[fl], sinpi[fl], and tanpi[fl]. Limited
testing on the cospi and sinpi reveal a max ULP less than 0.89;
while tanpi is more problematic with a max ULP less than 2.01
in the interval [0,0.5]. The algorithms used in these functions
are documented in {ks}_cospi.c, {ks}_sinpi.c, and s_tanpi.c.

Note. I no longer have access to a system with ld128 and
adequate support to compile and test the ld128 implementations
of these functions. Given the almost complete lack of input from
others on improvements to libm, I doubt that anyone cares. If
someone does care, the ld128 files contain a number of FIXME comments,
and in particular, while the polynomial coefficients are given
I did not update the polynomial algorithms to properly use the
coefficients.

PR: 218514
MFC after: 2 weeks


# 7702d940 08-Apr-2021 Dimitry Andric <dim@FreeBSD.org>

Avoid -pedantic warnings about using _Generic in __fp_type_select

When compiling parts of math.h with clang using a C standard before C11,
and using -pedantic, it will result in warnings similar to:

bug254714.c:5:11: warning: '_Generic' is a C11 extension [-Wc11-extensions]
return !isfinite(1.0);
^
/usr/include/math.h:111:21: note: expanded from macro 'isfinite'
^
/usr/include/math.h:82:39: note: expanded from macro '__fp_type_select'
^

This is because the block that enables use of _Generic is conditional
not only on C11, but also on whether the compiler advertises support for
C generic selections via __has_extension(c_generic_selections).

To work around the warning without having to pessimize the code, use the
__extension__ keyword, which is supported by both clang and gcc. While
here, remove the check for __clang__, as _Generic has been supported for
a long time by gcc too now.

Reported by: yuri
PR: 254714
MFC after: 1 week


# e369c79c 24-Oct-2020 Warner Losh <imp@FreeBSD.org>

Remove intel compiler support from math.h

The intel compiler support has badly decayed over the years. Stop
pretending that we support it. Note, I've stopped short of requiring
gcc builtin support with this commit since other compilers may be used
to build non-base software and we need to support those so more
investigation is needed before simplifying further.


# f68ff1ac 02-Nov-2019 Dimitry Andric <dim@FreeBSD.org>

Add __isnan()/__isnanf() aliases for compatibility with glibc and CUDA

Even though clang comes with a number of internal CUDA wrapper headers,
compiling sample CUDA programs will result in errors similar to:

In file included from <built-in>:1:
In file included from /usr/lib/clang/9.0.0/include/__clang_cuda_runtime_wrapper.h:204:
/usr/home/arr/cuda/var/cuda-repo-10-0-local-10.0.130-410.48/usr/local/cuda-10.0//include/crt/math_functions.hpp:2910:7: error: no matching function for call to '__isnan'
if (__isnan(a)) {
^~~~~~~
/usr/lib/clang/9.0.0/include/__clang_cuda_device_functions.h:460:16: note: candidate function not viable: call to __device__ function from __host__ function
__DEVICE__ int __isnan(double __a) { return __nv_isnand(__a); }
^

CUDA expects __isnan() and __isnanf() declarations to be available,
which are glibc specific extensions, equivalent to the regular isnan()
and isnanf().

To provide these, define __isnan() and __isnanf() as aliases of the
already existing static inline functions __inline_isnan() and
__inline_isnanf() from math.h.

Reported by: arrowd
PR: 241550
MFC after: 1 week


# e1b98d07 28-May-2017 Michal Meloun <mmel@FreeBSD.org>

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


# b8f41779 09-Jun-2016 Edward Tomasz Napierala <trasz@FreeBSD.org>

Fix frexpl() declaration to not include the field name.

MFC after: 1 month


# f7efd14d 15-Sep-2014 Steve Kargl <kargl@FreeBSD.org>

* 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


# 55ad7cd7 09-Aug-2014 Steve Kargl <kargl@FreeBSD.org>

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


# 3b5e0d0f 13-Jul-2014 Steve Kargl <kargl@FreeBSD.org>

* 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)


# e7d939bd 06-Jul-2014 Marcel Moolenaar <marcel@FreeBSD.org>

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


# a48e1f22 29-Dec-2013 Steve Kargl <kargl@FreeBSD.org>

* 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


# fb69d608 28-Jul-2013 David Chisnall <theraven@FreeBSD.org>

Restore the longer form of the _Generic. The short form does not work in C++.


# 6b69e627 29-Jul-2013 David Chisnall <theraven@FreeBSD.org>

Reenable the isnan(double) / isinf(double) declarations when targeting C89 + SUSv2 mode.


# b8f19c92 13-Jul-2013 David Chisnall <theraven@FreeBSD.org>

Cleaner support for type qualifiers.

Submitted by: Pasi Parviainen


# e21be487 13-Jul-2013 David Chisnall <theraven@FreeBSD.org>

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.


# 1583bcb4 12-Jul-2013 David Chisnall <theraven@FreeBSD.org>

Fix the build with C++ where __builtin_types_compatible_p is not allowed.


# 95f82796 11-Jul-2013 David Chisnall <theraven@FreeBSD.org>

Fix some typoes in math.h cleanup.


# a3fc79de 11-Jul-2013 David Chisnall <theraven@FreeBSD.org>

Cleanups to math.h that prevent namespace conflicts with C++.

Reviewed by: bde
MFC after: 3 days


# 998b640b 10-Jun-2013 David Schultz <das@FreeBSD.org>

Add implementations of acoshl(), asinhl(), and atanhl(). This is a
merge of the work done by bde and myself.


# 3ffff4ba 03-Jun-2013 Steve Kargl <kargl@FreeBSD.org>

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)


# 25a4d6bf 03-Jun-2013 David Schultz <das@FreeBSD.org>

Add logl, log2l, log10l, and log1pl.

Submitted by: bde


# b83ccea3 23-Jul-2012 Steve Kargl <kargl@FreeBSD.org>

Compute the exponential of x for Intel 80-bit format and IEEE 128-bit
format. These implementations are based on

PTP Tang, "Table-driven implementation of the exponential function
in IEEE floating-point arithmetic," ACM Trans. Math. Soft., 15,
144-157 (1989).

PR: standards/152415
Submitted by: kargl
Reviewed by: bde, das
Approved by: das (mentor)


# 8f62d384 26-May-2012 David Chisnall <theraven@FreeBSD.org>

Allow inclusion of libc++ <cmath> to work after including math.h

Submitted by: Yamaya Takashi
Reviewed by: das
MFC after: 1 week


# e481b863 12-Nov-2011 David Chisnall <theraven@FreeBSD.org>

Expose the unimplemented libm functions in the math.h header. This allows C++'s <cmath> to work without the compiler complaining that the C++ versions are calling implicitly-declared functions. You will still get a linker error when they are called. OpenBSD 5.0 claims to fully implement the C99 <math.h> stuff, so might be worth investigating...

Reviewed by: das
Approved by: dim (mentor)


# 15d5d9de 14-Oct-2011 David Schultz <das@FreeBSD.org>

Don't define FP_FAST_FMA on sparc64; with the recent fixes, fma() is
no longer "fast" on sparc64. (It really wasn't to begin with, since
the old implementation was using long doubles, and long doubles are
emulated in software on sparc64.)


# dfe5233b 12-Mar-2011 Steve Kargl <kargl@FreeBSD.org>

Implement the long double version for the cube root function, cbrtl.
The algorithm uses Newton's iterations with a crude estimate of the
cube root to converge to a result.

Reviewed by: bde
Approved by: das


# 177668d1 05-Dec-2010 David Schultz <das@FreeBSD.org>

Add log2() and log2f().


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# efd0f253 12-Jun-2010 David Schultz <das@FreeBSD.org>

Introduce __isnanf() as an alias for isnanf(), and make the isnan()
macro expand to __isnanf() instead of isnanf() for float arguments.
This change is needed because isnanf() isn't declared in strict POSIX
or C99 mode.

Compatibility note: Apps using isnan(float) that are compiled after
this change won't link against an older libm.

Reported by: Florian Forster <octo@verplant.org>


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# fbaabc11 14-Mar-2009 David Schultz <das@FreeBSD.org>

Namespace: scalb() is withdrawn from POSIX.


# ea8e2579 06-Feb-2009 David Schultz <das@FreeBSD.org>

C99 TC2 now wants FP_FAST_FMA* to be defined to 1, if the macros are
defined at all. See also: defect report #223.


# 4984f138 07-Jan-2009 David Schultz <das@FreeBSD.org>

Fix the types of INFINITY and NAN, which were broken in r131851. They
should both be floats, not doubles.

PR: 127795
Submitted by: Christoph Mallon
MFC after: 2 weeks


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 17303c62 31-Jul-2008 David Schultz <das@FreeBSD.org>

Add implementations of acosl(), asinl(), atanl(), atan2l(),
and cargl().

Reviewed by: bde
sparc64 testing resources from: remko


# f2dc0faa 19-Jun-2008 David Schultz <das@FreeBSD.org>

Implement fmodl.
Document fmodl and fix some errors in the fmod manpage.


# c7392fee 30-Mar-2008 David Schultz <das@FreeBSD.org>

Hook remquol() and remainderl() up to the build.


# 84c1c0a1 30-Mar-2008 David Schultz <das@FreeBSD.org>

Hook hypotl() and cabsl() up to the build.


# c6a4447b 01-Mar-2008 David Schultz <das@FreeBSD.org>

MI implementation of sqrtl(). This is very slow and should
be overridden when hardware sqrt is available.


# 71c11dd5 18-Feb-2008 David Schultz <das@FreeBSD.org>

Add tgammaf() as a simple wrapper around tgamma().


# 8e77cc64 17-Feb-2008 David Schultz <das@FreeBSD.org>

Add implementations of sinl(), cosl(), and tanl().

Submitted by: Steve Kargl <sgk@apl.washington.edu>


# 968b39e3 18-Jan-2008 David Schultz <das@FreeBSD.org>

Implement exp2l(). There is one version for machines with 80-bit
long doubles (i386, amd64, ia64) and one for machines with 128-bit
long doubles (sparc64). Other platforms use the double version.
I've only done runtime testing on i386.

Thanks to bde@ for helpful discussions and bugfixes.


# d3f9671a 13-Jan-2008 David Schultz <das@FreeBSD.org>

Implement rintl(), nearbyintl(), lrintl(), and llrintl().
Thanks to bde@ for feedback and testing of rintl().


# 45310fdb 19-Dec-2007 David Schultz <das@FreeBSD.org>

Grumble. DO declare logbl(), DON'T declare logl() just yet.
bde is going to commit logl() Real Soon Now.
I'm just trying to slow him down with merge conflicts.

Noticed by: bde


# 58c9a67e 19-Dec-2007 David Schultz <das@FreeBSD.org>

Remove the declaration of logl(). The relevant bits haven't been
committed yet, but the declaration leaked in when I added nan() and
friends.

Reported by: pav


# 4b6b5744 16-Dec-2007 David Schultz <das@FreeBSD.org>

Implement and document nan(), nanf(), and nanl(). This commit
adds two new directories in msun: ld80 and ld128. These are for
long double functions specific to the 80-bit long double format
used on x86-derived architectures, and the 128-bit format used on
sparc64, respectively.


# 9abb1ff6 07-Jan-2007 David Schultz <das@FreeBSD.org>

Implement modfl().


# 2f2ee27d 16-Apr-2005 David Schultz <das@FreeBSD.org>

Implement truncl() based on floorl().


# 07f3bc5b 07-Apr-2005 David Schultz <das@FreeBSD.org>

Add roundl(), lroundl(), and llroundl().


# f8d6ede6 04-Apr-2005 David Schultz <das@FreeBSD.org>

Implement exp2() and exp2f().


# 3b9141ee 24-Mar-2005 David Schultz <das@FreeBSD.org>

Implement and document remquo() and remquof().


# 21122bea 17-Mar-2005 David Schultz <das@FreeBSD.org>

Add missing prototypes for fma() and fmaf(), and remove an inaccurate
comment.


# 228ad57d 06-Mar-2005 David Schultz <das@FreeBSD.org>

- Define FP_FAST_FMA for sparc64, since fma() is now implemented using
sparc64's 128-bit long doubles.
- Define FP_FAST_FMAL for ia64.
- Prototypes for fmal, frexpl, ldexpl, nextafterl, nexttoward{,f,l},
scalblnl, and scalbnl.


# e1b61b5b 04-Feb-2005 David Schultz <das@FreeBSD.org>

Remove wrappers and other cruft intended to support SVID, mistakes in
C90, and other arcana. Most of these features were never fully
supported or enabled by default.

Ok: bde, stefanf


# d5580d09 22-Jan-2005 David Schultz <das@FreeBSD.org>

Add fma() and fmaf(), which implement a fused multiply-add operation.


# b6e65225 14-Jan-2005 David Schultz <das@FreeBSD.org>

Most libm routines depend on the rounding mode and/or set exception
flags, so they are not pure. Remove the __pure2 annotation from them.
I believe that the following routines and their float and long double
counterparts are the only ones here that can be __pure2:

copysign is* fabs finite fmax fmin fpclassify ilogb nan signbit

When gcc supports FENV_ACCESS, perhaps there will be a new annotation
that allows the other functions to be considered pure when FENV_ACCESS
is off.

Discussed with: bde


# 71936f35 14-Jan-2005 David Schultz <das@FreeBSD.org>

Braino. Revert rev 1.50.

Pointy hat to: das


# ce4e53c4 14-Jan-2005 David Schultz <das@FreeBSD.org>

Set math_errhandling to MATH_ERREXCEPT. Now that we have fenv.h, we
basically support this, subject to gcc's lack of FENV_ACCESS support.
In any case, the previous setting of math_errhandling to 0 is not
allowed by POSIX.


# c165c4b9 14-Jan-2005 David Schultz <das@FreeBSD.org>

Remove some #if 0'd code.


# 43295fac 13-Jan-2005 Stefan Farfeleder <stefanf@FreeBSD.org>

Implement and document ceill().


# 17f418f9 12-Jan-2005 Stefan Farfeleder <stefanf@FreeBSD.org>

Implement floorl().


# a7d82b71 12-Jan-2005 Stefan Farfeleder <stefanf@FreeBSD.org>

Whitespace nit.


# 10c9ffa4 11-Jan-2005 David Schultz <das@FreeBSD.org>

Add MI implementations of [l]lrint[f]() and [l]lround[f]().

Discussed with: bde


# 2fd3a32e 11-Oct-2004 Stefan Farfeleder <stefanf@FreeBSD.org>

Add and document ilogbl(), a long double version of ilogb().


# d622ef69 16-Sep-2004 David Schultz <das@FreeBSD.org>

Further refine some #ifs:
- Simplify the logic by using __GNUC_PREREQ__.
Suggested by stefanf.
- Make math.h compile with old (pre-8.0) versions of icc.
Submitted by sf [sic].


# ec79bc0d 19-Jul-2004 David Schultz <das@FreeBSD.org>

Fix two bugs in the signbit() macro, which was implemented last year:

- It was added to libc instead of libm. Hopefully no programs rely
on this mistake.

- It didn't work properly on large long doubles because its argument
was converted to type double, resulting in undefined behavior.


# 9979bae3 17-Jul-2004 Stefan Farfeleder <stefanf@FreeBSD.org>

Fix minor namespace pollution: The prototypes for f{dim,max,min}(),
nearbyint(), round() and trunc() shouldn't be visible when compiling with
-D_XOPEN_SOURCE=500.


# 205d3300 16-Jul-2004 David Schultz <das@FreeBSD.org>

Tweak the conditions under which certain gcc builtins are used:

- Unlike the builtin relational operators, builtin floating-point
constants were not available until gcc 3.3, so account for this.[1]

- Apparently some versions of the Intel C Compiler fallaciously define
__GNUC__ without actually being compatible with the claimed gcc
version. Account for this, too.[2]

[1] Noticed by: Christian Hiris <4711@chello.at>
[2] Submitted by: Alexander Leidinger <Alexander@Leidinger.net>


# 240dbabf 08-Jul-2004 David Schultz <das@FreeBSD.org>

Implement the classification macros isfinite(), isinf(), isnan(), and
isnormal() the hard way, rather than relying on fpclassify(). This is
a lose in the sense that we need a total of 12 functions, but it is
necessary for binary compatibility because we have never bumped libm's
major version number. In particular, isinf(), isnan(), and isnanf()
were BSD libc functions before they were C99 macros, so we can't
reimplement them in terms of fpclassify() without adding a dependency
on libc.so.5. I have tried to arrange things so that programs that
could be compiled in FreeBSD 4.X will generate the same external
references when compiled in 5.X. At the same time, the new macros
should remain C99-compliant.

The isinf() and isnan() functions remain in libc for historical
reasons; however, I have moved the functions that implement the macros
isfinite() and isnormal() to libm where they belong. Moreover,
half a dozen MD versions of isinf() and isnan() have been replaced
with MI versions that work equally well.

Prodded by: kris


# b2d5d0b3 08-Jul-2004 David Schultz <das@FreeBSD.org>

Define the following macros in terms of [gi]cc builtins when the
builtins are available: HUGE_VAL, HUGE_VALF, HUGE_VALL, INFINITY,
and NAN. These macros now expand to floating-point constant
expressions rather than external references, as required by C99.
Other compilers will retain the historical behavior. Note that
it is not possible say, e.g.
#define HUGE_VAL 1.0e9999
because the above may result in diagnostics at translation time
and spurious exceptions at runtime. Hence the need for compiler
support for these features.

Also use builtins to implement the macros isgreater(),
isgreaterequal(), isless(), islessequal(), islessgreater(),
and isunordered() when such builtins are available.
Although the old macros are correct, the builtin versions
are much faster, and they avoid double-expansion problems.


# 9428e108 05-Jul-2004 David Schultz <das@FreeBSD.org>

Add C99's nearbyint{,f}() functions as wrappers around rint().
These trivial implementations are about 25 times slower than
rint{,f}() on x86 due to the FP environment save/restore.
They should eventually be redone in terms of fegetround() and
bit fiddling.


# 4f82cb46 30-Jun-2004 David Schultz <das@FreeBSD.org>

Implement and document fdim{,f,l}, fmax{,f,l}, and fmin{,f,l}.


# 62247e90 20-Jun-2004 David Schultz <das@FreeBSD.org>

Declare scalbln(), scalblnf(), trunc(), and truncf().


# 83bc8931 19-Jun-2004 Stefan Farfeleder <stefanf@FreeBSD.org>

Our MI implementation of ilogb() returns -INT_MAX for the argument 0.0 rather
than INT_MIN, so adjust FP_ILOGB0 to reflect this. Use <machine/_limits.h> for
INT_MAX's value while there.

Reviewed by: standards@


# 207bc1d7 09-Jun-2004 David Schultz <das@FreeBSD.org>

Include <sys/cdefs.h> earlier to get the various visibility constants.
Previously, we were relying on <sys/_types.h> to include it implicitly.


# d0f13633 07-Jun-2004 David Schultz <das@FreeBSD.org>

Add round(3) and roundf(3) and the associated documentation.

PR: 59797
Submitted by: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
Reviewed by: bde (earlier version, last year)


# b60cb13f 07-May-2004 Stefan Farfeleder <stefanf@FreeBSD.org>

Add an implementation of copysignl(), a long double version of copysign().

Approved by: das (mentor)


# 8f3f7c66 24-Apr-2004 David Schultz <das@FreeBSD.org>

Make sure that symbols are declared in math.h iff the appropriate
namespaces are visible. Previously, math.h failed to hide some C99-,
XSI-, and BSD-specific symbols in certain compilation environments.

The referenced PR has a nice listing of the appropriate conditions for
making symbols visible in math.h. The only non-stylistic difference
between the patch in the PR and this commit is that I superfluously
test for __BSD_VISIBLE in a few places to be more explicit about which
symbols have historically been part of the FreeBSD environment.

PR: 65939
Submitted by: Stefan Farfeleder <stefan@fafoe.narf.at>


# 334c760e 24-Apr-2004 David Schultz <das@FreeBSD.org>

Remove a stale comment referring to values.h, which has never been
part of FreeBSD.

PR: 65939


# 6eb2d83e 11-Mar-2004 Bruce Evans <bde@FreeBSD.org>

Initial support for C99's (or is it POSIX.1-2001's?) MATH_ERRNO,
MATH_ERREXCEPTION and math_errhandling, so that C99 applications at
least have the possibility of determining that errno is not set for
math functions. Set math_errhandling to the non-standard-conforming
value of 0 for now to indicate that we don't support either method
of reporting errors. We intentionally don't support MATH_ERRNO
because errno is a mistake, and we are missing support for
MATH_ERREXCEPTION (<fenv.h>, compiler support for <fenv.h>, and
actually setting the exception flags correctly).


# 29bd23ab 23-Oct-2003 Dag-Erling Smørgrav <des@FreeBSD.org>

Add prototypes for all long double functions in C99. Leave them all
#if 0'd out, except for fabsl(3) which I've implemented.


# 6f9622a9 22-May-2003 Mike Barcroft <mike@FreeBSD.org>

Fix two misuses of __BSD_VISIBLE.

Submitted by: bde
Approved by: re


# 6d3bd953 04-Apr-2003 David Schultz <das@FreeBSD.org>

Fix braino in definition of isfinite().

Noticed by: marcus
Pointy hat to: das


# 457f6cd2 26-Feb-2003 Warner Losh <imp@FreeBSD.org>

- gamma_r, lgamma_r, gammaf_r, and lgammaf_r were protected by _REENTRANT
in math.h; the consensus here was that __BSD_VISIBLE was correct instead.

- gamma_r, lgamma_r, gammaf_r, and lgammaf_r had no documentation in the
lgamma(3) manpage.

Reviewed by: standards@
Submitted by: Ben Mesander


# 5d62092f 12-Feb-2003 Mike Barcroft <mike@FreeBSD.org>

o Implement C99 classification macros isfinite(), isinf(), isnan(),
isnormal(). The current isinf() and isnan() are perserved for
binary compatibility with 5.0, but new programs will use the macros.
o Implement C99 comparison macros isgreater(), isgreaterequal(),
isless(), islessequal(), islessgreater(), isunordered().

Submitted by: David Schultz <dschultz@uclink.Berkeley.EDU>


# 8e9b2831 11-Feb-2003 Mike Barcroft <mike@FreeBSD.org>

Implement C99's signbit() macro.


# 8cf5ed51 08-Feb-2003 Mike Barcroft <mike@FreeBSD.org>

Implement fpclassify():
o Add a MD header private to libc called _fpmath.h; this header
contains bitfield layouts of MD floating-point types.
o Add a MI header private to libc called fpmath.h; this header
contains bitfield layouts of MI floating-point types.
o Add private libc variables to lib/libc/$arch/gen/infinity.c for
storing NaN values.
o Add __double_t and __float_t to <machine/_types.h>, and provide
double_t and float_t typedefs in <math.h>.
o Add some C99 manifest constants (FP_ILOGB0, FP_ILOGBNAN, HUGE_VALF,
HUGE_VALL, INFINITY, NAN, and return values for fpclassify()) to
<math.h> and others (FLT_EVAL_METHOD, DECIMAL_DIG) to <float.h> via
<machine/float.h>.
o Add C99 macro fpclassify() which calls __fpclassify{d,f,l}() based
on the size of its argument. __fpclassifyl() is never called on
alpha because (sizeof(long double) == sizeof(double)), which is good
since __fpclassifyl() can't deal with such a small `long double'.

This was developed by David Schultz and myself with input from bde and
fenner.

PR: 23103
Submitted by: David Schultz <dschultz@uclink.Berkeley.EDU>
(significant portions)
Reviewed by: bde, fenner (earlier versions)


# 83999f5a 31-Oct-2002 Archie Cobbs <archie@FreeBSD.org>

Re-apply the previously backed-out commit that fixes the problem where
HUGE_VAL is not properly aligned on some architectures. The previous
fix now works because the two versions of 'math.h' (include/math.h
and lib/msun/src/math.h) have since been merged into one.

PR: bin/43544


# bf2f52b5 23-Oct-2002 Mark Murray <markm@FreeBSD.org>

Remove duplicate declaration.


# 54e9b367 01-Oct-2002 Bruce Evans <bde@FreeBSD.org>

Fixed a last-minute editing error in previous commit. nfs and/or cvs
replaced a 14-byte change in the middle of the file with 14 NULs at EOF
despite or because of aborting the initial commit to pick up the change.


# 219cbe10 01-Oct-2002 Bruce Evans <bde@FreeBSD.org>

Merged all interesting difference between the old math.h and the current
one into the latter and removed the former.

This works around the bug that some broken Makefiles add -I.../src/include
to CFLAGS, resulting in the old math.h being preferred and differences
between the headers possibly being fatal.

The merge mainly involves declaring some functions as __pure2 although
they are not yet all strictly free of side effects.

PR: 43544


# ae8a4b2f 20-Sep-2002 Archie Cobbs <archie@FreeBSD.org>

Revert previous commit to unbreak world until we figure out the
right way to do it.


# f5f12722 19-Sep-2002 Archie Cobbs <archie@FreeBSD.org>

Fix a problem with the definition of HUGE_VAL causing the gcc warning
"cast increases required alignment of target type" on some platforms.

Reviewed by: bde


# 46d7c297 26-Mar-2002 Bruce Evans <bde@FreeBSD.org>

Resurrect Lite1's gamma() as C99's tgamma(). Minimal changes.


# 6898f8c4 26-Mar-2002 Bruce Evans <bde@FreeBSD.org>

Fixed some minor style bugs.


# 69160b1e 21-Mar-2002 David E. O'Brien <obrien@FreeBSD.org>

Remove __P() usage.


# ef1ee63e 13-Dec-2001 Alexey Zelkin <phantom@FreeBSD.org>

Fix style bugs (mostly remove 'extern' from function prototypes)

Inspired by: conversation with bde


# d28011e5 13-Jun-2001 Ruslan Ermilov <ru@FreeBSD.org>

Added skeleton <complex.h> (aligned with the POSIX.1-200x), mostly
to fix the "-nostdinc WARNS=X" breakage caused by broken prototypes
for cabs() and cabsl() in <math.h>.

Reimplemented cabs() and cabsl() using new complex numbers types and
moved prototypes from <math.h> to <complex.h>.


# d6f56cfc 26-Mar-2000 David E. O'Brien <obrien@FreeBSD.org>

MFS: Add a "magic" comment to help fixincludes realize it doesn't need to
modify this file when building GCC 2.96 [by hand or via the port].

Submitted by: Zack Weinberg <zack@wolery.cumb.org>


# 7f3dea24 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 5a36b24a 22-Apr-1998 Paul Traina <pst@FreeBSD.org>

Back out last change


# d84b1410 22-Apr-1998 Paul Traina <pst@FreeBSD.org>

Fix cabs and cabsf definitions to be prototypes.


# 6a9280be 31-Aug-1997 Bruce Evans <bde@FreeBSD.org>

Hide the declaration of `struct exception' from C++, since it conflicts
with the standard C++ `class exception'. This makes matherr() difficult
to use in C++. Small loss.


# 7e546392 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 6c06b4e2 29-May-1995 Rodney W. Grimes <rgrimes@FreeBSD.org>

Remove trailing whitespace.


# 3a8617a8 19-Aug-1994 Jordan K. Hubbard <jkh@FreeBSD.org>

J.T. Conklin's latest version of the Sun math library.

-- Begin comments from J.T. Conklin:
The most significant improvement is the addition of "float" versions
of the math functions that take float arguments, return floats, and do
all operations in floating point. This doesn't help (performance)
much on the i386, but they are still nice to have.

The float versions were orginally done by Cygnus' Ian Taylor when
fdlibm was integrated into the libm we support for embedded systems.
I gave Ian a copy of my libm as a starting point since I had already
fixed a lot of bugs & problems in Sun's original code. After he was
done, I cleaned it up a bit and integrated the changes back into my
libm.
-- End comments

Reviewed by: jkh
Submitted by: jtc