Changeset 997 for trunk/test/math


Ignore:
Timestamp:
Sep 29, 2011, 9:10:00 PM (10 years ago)
Author:
sam
Message:

core: add boolean operators on real numbers, add unit tests for that,
and simplify the Remez code accordingly.

File:
1 edited

Legend:

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

    r996 r997  
    2222static int const ORDER = 8;
    2323
    24 static real compute_pi()
    25 {
    26     /* Approximate Pi using Machin's formula: 16*atan(1/5)-4*atan(1/239) */
    27     real sum = 0.0, x0 = 5.0, x1 = 239.0;
    28     real const m0 = -x0 * x0, m1 = -x1 * x1, r16 = 16.0, r4 = 4.0;
    29 
    30     /* Degree 240 is required for 512-bit mantissa precision */
    31     for (int i = 1; i < 240; i += 2)
    32     {
    33         sum += r16 / (x0 * (real)i) - r4 / (x1 * (real)i);
    34         x0 *= m0;
    35         x1 *= m1;
    36     }
    37     return sum;
    38 }
    39 
    4024/* The function we want to approximate */
    4125static real myfun(real const &x)
    4226{
    43     static real const half_pi = compute_pi() * (real)0.5;
    4427    static real const one = 1.0;
    45     if (x == (real)0.0 || x == (real)-0.0)
    46         return half_pi;
    47     return sin(x * half_pi) / x;
     28    if (!x)
     29        return real::R_PI_2;
     30    return sin(x * real::R_PI_2) / x;
    4831    //return cos(x) - one;
    4932    //return exp(x);
Note: See TracChangeset for help on using the changeset viewer.