Version 2 (modified by sam, 9 years ago) (diff)


Remez tutorial first example: exp(x)

In this section we are going to approximate the exp(x) function using a polynomial.

This should be a hands-on example of the Lol Remez toolkit.

Source code

#include "lol/math/real.h"
#include "lol/math/remez.h"

using lol::real;
using lol::RemezSolver;

real f(real const &x) { return exp(x); }

int main(int argc, char **argv)
    RemezSolver<4, real> solver;
    solver.Run(-1, 1, f, 30);
    return 0;

What does this mean?

  • we declare function f which returns the exponential of 'x'.
  • we create a RemezSolver object for 4th-degree polynomials and real numbers.
  • we run the solver on the [-1,1] range, approximating function f for 30 iterations.


If you are using LolRemez, just put the above source code in remez.cpp and type:



To launch the test, type:


After all the iterations the output should be as follows:

Final error: 5.462771976237482581009771665937582411463e-4
Polynomial estimate:

Using the results

The above results can be used in a C++ implementation:

double fastexp(double x)
    const double a0 = 1.000090756764725753887362987792025308996;
    const double a1 = 9.973086551667860566788019540269306006270e-1;
    const double a2 = 4.988332174505582284710918757571761729419e-1;
    const double a3 = 1.773462612793916519454714108029230813767e-1;
    const double a4 = 4.415666059995979611944324860870682575219e-2;

    return a0 + x * (a1 + x * (a2 + x * (a3 + x * a4)));

Analysing the results

Plotting the real exponential function and our fastexp function gives the following curves:

Attachments (2)

Download all attachments as: .zip