Changeset 1005 for trunk/test/math


Ignore:
Timestamp:
Oct 4, 2011, 3:35:45 PM (9 years ago)
Author:
sam
Message:

test: add support for relative error in the Remez exchange test program.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/math/remez.cpp

    r997 r1005  
    1414
    1515#include <cstring>
     16#include <cstdio>
    1617
    1718#include "core.h"
     
    2021
    2122/* The order of the approximation we're looking for */
    22 static int const ORDER = 8;
     23static int const ORDER = 4;
    2324
    2425/* The function we want to approximate */
    2526static real myfun(real const &x)
    2627{
    27     static real const one = 1.0;
    28     if (!x)
    29         return real::R_PI_2;
    30     return sin(x * real::R_PI_2) / x;
    31     //return cos(x) - one;
    32     //return exp(x);
     28    return exp(x);
     29    //if (!x)
     30    //    return real::R_PI_2;
     31    //return sin(x * real::R_PI_2) / x;
     32}
     33
     34static real myerror(real const &x)
     35{
     36    return myfun(x);
     37    //return real::R_1;
    3338}
    3439
     
    206211static void remez_findzeroes(real *coeff, real *zeroes, real *control)
    207212{
    208     /* FIXME: this is fake for now */
    209213    for (int i = 0; i < ORDER + 1; i++)
    210214    {
     
    278282                    final = maxerror;
    279283                control[i] = (a + b) * (real)0.5;
    280                 printf("%g (in %g)\n", (double)maxerror, (double)control[i]);
     284                printf("%g (at %g)\n", (double)maxerror, (double)control[i]);
    281285                break;
    282286            }
     
    314318            mat.m[i][n] = sum;
    315319        }
    316         mat.m[i][ORDER + 1] = (real)(-1 + (i & 1) * 2);
     320        if (i & 1)
     321            mat.m[i][ORDER + 1] = fabs(myerror(control[i]));
     322        else
     323            mat.m[i][ORDER + 1] = -fabs(myerror(control[i]));
    317324    }
    318325
Note: See TracChangeset for help on using the changeset viewer.