[Contents] [TitleIndex] [WordIndex

Accurate and Portable Elementary Functions (A.P.E.F.)


This page is obsolete. This project is not part of the Scilab list of ideas anymore, since it has already been done in 2011.


Scilab provides several elementary functions such as pow (i.e. x^y), sin, tan, exp, log, etc... These functions are provided by the mathematical library associated with the compiler. More specifically:

This implies that the results provided by the sine function, for example, are potentially not the same for Windows and for Linux. Still, for most common computations, the results are exactly the same. But, for some inputs x and some functions, the results are drastically different. This is especially the case when the function is ill-conditionned for some x.

GSOC 2011

Some work has been done in the context of the GSoC 2011. The work has been published in a dedicated git branch: http://cgit.scilab.org/scilab/log/?h=apef

See the list of reports:

To sum up, the main problem of the final result is the low performances of the library. In the context of the GSoC 2012, performance could be improved.

Some examples

In this section, we describe some examples of bugs which were detected with respect to accuracy of the elementary functions.

Bug #4048: The pow function

This bug is [http://bugzilla.scilab.org/show_bug.cgi?id=4048 #4048].

On Linux 32 bits, we get :

 ans  =

On Windows 32 bits, we get:

 ans  =

The floating point representation is

fl(0.9999999999999999)= 9007199254740991 * 2^-53

And Wolfram Alpha produces :


The condition number for this case is 1.8D+16, which is a bad as can be.

It is due to a bug in the glibc on double precision: http://sources.redhat.com/bugzilla/show_bug.cgi?id=706

Bug #8617: The cos function is not accurate for some x on Linux 32 bits

This is the bug [http://bugzilla.scilab.org/show_bug.cgi?id=8617 #8617].

The test which fails in cos.tst is the comparison of the exact and computed value of cos(x), for x=1.570796326794896558, which is a 18 digits decimal representation of pi/2. The failure of this test indicates that the computed value is off by more than 1 ulp from the expected result. Actually, the error is much worse than a few ulps.

With Scilab 5.3.0 on Linux 32 bits Ubuntu 10.04:

ans  =

With Scilab 5.3.0 on Windows XP 32 bits:

ans  =

The exact value of cos(%pi/2) is :

cos(7074237752028440 * 2^(0-53+1))=
6.123233995736765886130329661375001464640377798836283... × 10^-17

as given by Wolfram Alpha. Hence, the relative error on each of these platforms is given by:

-->expected = 6.123233995736765886D-17;

which produces :

This shows that the cos function provided by Visual on Windows is exact on x=1.570796326794896558, while the cos function provided by gcc on this particular Linux 32 bits only has ~5 significant digits, which is not good at all. We may be satisfied by 15 digits, or even the exact result, but not less. The argument reduction algorithm in cos cannot justify such a gross innacuracy, since the value x=1.570796326794896558 is not large (the point x=1.e16 would be more questionable).

What do we need

The ultimate solution to fix these issues is to use a library which is correctly rounded for all inputs x. This is still a research topic for many functions, but is solved for some specific functions. On the other hand, if we were using the same library on all platforms, the computations should (at least partially) produce the same results on all platforms. The reason why this will solve only partially the problem is because compiling options or processor's specific features can lead to different floating point results, for example caused by the use of extended precision.

In the two next sections, we suggest libraries which could be connected to Scilab.



Developed at Sun Microsystems, Inc.

FDLIBM (Freely Distributable LIBM) is a C math library for machines that support IEEE 754 floating-point arithmetic. In this release, only double precision is supported.

FDLIBM is intended to provide a reasonably portable (see assumptions below), reference quality (below one ulp for major functions like sin,cos,exp,log) math library (libm.a). For a copy of FDLIBM, please see


Fdlibm provides the following functions:



A reference correctly-rounded library of basic double-precision transcendental elementary functions.

libmcr is offered as a reference library for selected double-precision transcendental elementary functions. The library is supplied as source code allowing the researcher to build it for a variety of machines.

The code is distributed under Sun's Public Source Code License. All library source code is distributed with the license detailing use and redistribution limitations.

The code was developed and is distributed and maintained by Sun's Floating Point Libraries group.

Included Functions:


The purpose of this project is to offer a mathematical library (libm) with proven, IEEE-754 compliant, correct rounding in the four rounding modes, and performances comparable to standard libms.

CRlibm, an efficient and proven correctly-rounded mathematical library

CRlibm is a free mathematical library (libm) which provides:

CRlibm is distributed under the GNU Lesser General Public License (LGPL). Included in the distribution is an extensive documentation with the proof of each function (currently more than 100 pages), as well as all the Maple scripts used to develop the functions. This makes this library an excellent tutorial on software elementary function development.

The CRlibm library also includes a lightweight library for multiple precision, scslib (Software Carry Save Library). This library has been developed specifically to answer the needs of the CRlibm project: precision up to a few hundred bits, portability, compatibility with IEEE floating-point, performance comparable to or better than GMP, small footprint. It uses a data-structure which allows to avoid carry propagations during multiple-precision multiplications. Supported operations are essentially addition/subtraction and multiplication, and conversions. This library is independent from CRlibm.

The authors of the Crlibm project are



DIGITEO - Michaël Baudin

2022-09-08 09:26