The C libm seems to be the de facto standard for mathematical functions.
Libm specification ?
Some information can be found on in the ISO standards, for example in C99 standard (ISO/IEC 9899:[2011|1999|1990]) [6]. The main libm header, namely math.h is described in Section 7.2 of this standard.
Section 5.3.4.2.2-§5 covers the characteristics of floating types. In particular it states that:
“The accuracy of the floating-point operations (+, -, *, /) and of the library functions in and that return floating-point results is implementation defined,”. This means that there is no requirement on operation nor function accuracy: not even faithful rounding is required !
Section 6.5-§8 of standard covers the possibility for expression contraction. It states the following:
“A floating expression may be contracted, that is, evaluated as though it were an atomic operation, thereby omitting rounding errors implied by the source code and the expression evaluation method.75) The FP_CONTRACT pragma in provides a way to disallow contracted expressions. Otherwise, whether and how expressions are contracted is implementation-defined.”
This seems to indicate that function composition simplification, a.k.a function expression contraction, is allowed.
The standard’s Annex F 9 (which is normative) covers the list of functions and indicates which behaviours are expected in special cases.
Online libm documentations are available in [7, 8].
The libm is used as a basis for various other languages, e.g. C++ https://en.cppreference.com/w/cpp/header/cmath.
Libm implementation
Most libm implementations originate either from fdlibm or IBM’s libultim [4]
OpenLibm: (https://openlibm.org/, https://github.com/JuliaMath/openlibm )
Supported by the JuliaProject
“The OpenLibm code derives from the FreeBSD msun and OpenBSD libm implementations, which in turn derive from FDLIBM 5.3. Over and above that, OpenLibm itself has received a number of patches to make it platform independent and portable.”
FDLibm: Freely Distributable Libm (http://www.netlib.org/fdlibm/)
Version 5.3, developed at Sun Microsystems, Inc.
Newlib (https://sourceware.org/newlib/)
C libraries for embedded systems
CRlibm: https://gforge.inria.fr/scm/browser.php?group_id=5929&extra=crlibm
Correctly rounded library (error less or equal to half an ulp)
Glibc’s libm (https://sourceware.org/glibc/wiki/libm)
https://sourceware.org/git?p=glibc.git;a=tree;f=math;hb=HEAD
MUSL’s libm (https://git.musl-libc.org/cgit/musl/tree/src/math)
Sleef https://sleef.org/
Focus on fast SIMD implementations
APMathLibm, Libultim (https://www.math.utah.edu/cgi-bin/man2html.cgi?/usr/local/man/man3/libultim.3)
Sun Microsystems libMCR https://github.com/simonbyrne/libmcr
http://www.math.utah.edu/cgi-bin/man2html.cgi?/usr/local/man/man3/libmcr.3
The standard libm provides the most current mathematical functions. There are extension for “special” functions: Mathematical Special Functions: https://en.cppreference.com/w/cpp/numeric/special_functions
Open questions:
How much code came from Sun Microsystem development ?
What are the libraries’ performances ?
What are the libraries’ accuracies ? [crlibm, libultim and libmcr seems to fall in the correctly rounded category]
What are the libraries’ specificities ?
Intel MKL is another reference (also not open source and not portable)
Bibliography
- [0] Towards the post-ultimate libm, Dinechin et al (http://www.acsel-lab.com/arithmetic/arith17/papers/ARITH17_Dinechin.pdf)
- [1] https://indico.esa.int/event/239/contributions/2254/attachments/1842/2144/0900b_-_Arregui.pdf
- [2] https://www.vinc17.net/research/papers/ieeetc2009-powr.pdf
- [3] “Fast evaluation of elementary mathematical functions with correctly rounded last bit
- [4] https://www.openwall.com/lists/musl/2012/01/23/1 : discussion on musl mailing list about libm implementation choices
- [5] http://nsz.repo.hu/libm libm for musl
- [6] http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
- https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf
- [7] https://en.cppreference.com/w/c/numeric/math
- [8] Oracle doc on libm: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_lib.html
No comments:
Post a Comment