Re: sin(x) for large x

Discussion in 'C Programming' started by glen herrmannsfeldt, May 18, 2004.

  1. James Giles wrote:

    (someone wrote)

    >>I submit, that if a change in the least significant bit of the
    >>argument (which is very frequently but a finite-precision rational
    >>approximation to a real in itself) is larger than pi, the best thing
    >>to return is 'NaN', and most of the time the users should be trapping
    >>on NaN's.

    In the days before NaN's it could have just been a fatal
    error. In one IBM manual on the DSIN function, (comparable
    to the C sin function)...

    They limit the domain to +/- PI*2**50, which I believe leaves
    four bits after the binary point (or one digit after the
    hexadecimal point for purists). The then quote relative and
    absolute accuracy figures as follows:

    Relative Absolute
    Max Std.Dev. Max. Std.Dev.

    abs(X)<= PI/2 3.60e-16 4.82e-17 7.74e-17 1.98e-17
    pi/2<abs(X)<=10 1.64e-16 6.49e-17
    10<abs(X)<=100 2.68e-15 1.03e-15

    So, in the range where they expect most users to use
    the function they give reasonably detailed numbers. Do any
    of the libraries more modern than this, from other companies,
    give this information?

    They also give details on the argument reduction used:

    Divide abs(x) by pi/4 and separate into integer part (q),
    and fraction part (r). 0<=r<1.

    If cosine is desired, add 2 to q. If sine is desired and
    x is negative add 4 to q.

    Using q0= q mod 8,

    for q0=0 use sin((pi/4)*r)
    q0=1 cos((pi/4)*(1-r))
    q0=2 cos((pi/4)*r)
    q0=3 sin((pi/4)*(1-r))
    q0=4 -sin((pi/4)*r)
    q0=5 -cos((pi/4)*(1-r))
    q0=6 -cos((pi/4)*r)
    q0=7 -sin((pi/4)*(1-r))

    Using polynomial interpolation of degree 6 in r**2 for sin,
    or degree 7 in r**2 for cosine. In either case, the interpolation
    points were the roots of the Chebyshev polynomial of one higher
    degree. The maximum relative error for the sin polynomial
    is 2**-58, of the cosine polynomial is 2**-64.3.

    Not that all the details are important here, but the amount
    of detail that went into the explanation. This is from
    the Application Programming: Library Reference, meant to
    be read by application programmers.

    > Well, that argument would have more support if we were
    > using intervals, or significance arithmetic, or some other
    > means to denote the accuracy to which values were known.
    > Then the transition from significant to NaN wouldn't be just
    > a sudden jump. The answers would be larger and larger
    > intervals (or fewer and fewer digits) until the whole interval
    > [-1.0, 1.0] was returned (or, "no significance"). Without that,
    > where are you going to draw the line?

    In the case above, no accuracy numbers were given past 100,
    and one can see how fast the accuracy decays at that point.

    > NaN would be a good representation for "no significance". But
    > how do you propose telling the naive user that there was some,
    > but not much, significance? And, within ordinary ranges, it's not
    > entirely foolish to want a full precision answer (so, whatever
    > your solution is, you need to allow real experts to turn it off).

    Real experts can do their own range reduction in the way
    appropriate to the problem they are working on.

    -- glen
    glen herrmannsfeldt, May 18, 2004
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. aj
    Dec 31, 2005
  2. Blinky the Shark

    Image Viewer - A Sin?

    Blinky the Shark, Apr 15, 2005, in forum: HTML
    Blinky the Shark
    Apr 21, 2005
  3. Replies:
    Sep 9, 2003
  4. Alexander Stippler

    why do I need ::sin, not std::sin?

    Alexander Stippler, Jun 4, 2004, in forum: C++
    Pete Becker
    Jun 5, 2004
  5. Sloan

    How to plot Sin wave ?

    Sloan, Aug 3, 2004, in forum: C++
    Uwe Schnitker
    Aug 5, 2004

Share This Page