Changes between Version 11 and Version 12 of research/trig


Ignore:
Timestamp:
Dec 30, 2011, 11:32:22 PM (7 years ago)
Author:
sam
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • research/trig

    v11 v12  
     1[[TOC]]
    12= Trigonometric functions =
    23
     
    78 * OpenBSD [http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libm/src/k_sin.c?rev=1.3;content-type=text%2Fplain sin(double)].
    89 * OpenBSD [http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libm/src/k_sinf.c?rev=1.3;content-type=text%2Fplain sinf(float)].
     10
     11== Evaluating minimax polynomials ==
     12
     13Let’s check how much an error on the last bit affects `float` variables, using relative error:
     14
     15{{{
     16#!cpp
     17for (float f = 1e-25f; f < 50.0f; f *= 1.001f)
     18{
     19    union { float f; uint32_t x; } u = { f }, v = u, w = u;
     20    ++v.x;
     21    --w.x;
     22    printf("%e: %e %e\n", u.f, (v.f - u.f) / u.f, (u.f - w.f) / u.f);
     23}
     24}}}
     25
     26Plotting the results gives the answer: between `5.96e-8` and `1.19e-7`.
     27
     28How about `double`?
     29
     30{{{
     31#!cpp
     32for (double d = 1e-25; d < 50.0; d *= 1.001)
     33{   
     34    union { double d; uint64_t x; } u = { d }, v = u, w = u;
     35    ++v.x;
     36    --w.x;
     37    printf("%e: %e %e\n", u.d, (v.d - u.d) / u.d, (u.d - w.d) / u.d);
     38}   
     39}}}
     40
     41Result: between `1.11e-16` and `2.22e-16`.
    942
    1043== Minimax polynomial for sin(x) ==