Re: Accuracy of tan()?
From: Ray Koopman (koopman_at_sfu.ca)
Date: 06/28/04
- Next message: John Appleyard: "Re: Cheque clearing"
- Previous message: Scientific Books: "Scientific books: cheap sell-out of the library"
- In reply to: Everett M. Greene: "Accuracy of tan()?"
- Next in thread: Gerry Thomas: "Re: Accuracy of tan()?"
- Messages sorted by: [ date ] [ thread ]
Date: 28 Jun 2004 10:55:49 -0700
mojaveg@iwvisp.com (Everett M. Greene) wrote in message
news:<20040623.7A1BB70.A513@mojaveg.iwvisp.com>...
> We have a situation where we have a tan() function
> implemented in single-precision floating point
> arithmetic and a test case is tan(-1.570796). We
> are getting results of
>
> - 3060018.
> - 3185560.75
> - 3185560.708
> - 3560236.5
> - 5340352.5
> -37320540.2
>
> depending on the implementation.
>
> How does one define the accuracy of the tangent function
> near the odd multiples of pi/2 and which of the above is
> the "better" result?
>
> As far as I'm concerned, any big number is good enough
> in the vicinity of odd multiples of pi/2 since one
> has an ill-formed problem if using tan() in these regions.
For x near pi/2, the trick is get a good (= low relative error)
representation of pi/2-x, so we can use tan x = cot(pi/2-x).
For the case where x is an ordinary floating pt number,
let a = the ordinary floating pt representation of pi/2,
and b = the ordinary floating pt representation of pi/2-a,
so that a+b would give a double-length representation of pi/2
if the extra bits were kept. Then cot((a-x)+b) should work,
provided the compiler honors the parenthesization.
If x is not an ordinary floating pt number then the same logic applies
but the details of its application will depend on the specifics of the
situation.
- Next message: John Appleyard: "Re: Cheque clearing"
- Previous message: Scientific Books: "Scientific books: cheap sell-out of the library"
- In reply to: Everett M. Greene: "Accuracy of tan()?"
- Next in thread: Gerry Thomas: "Re: Accuracy of tan()?"
- Messages sorted by: [ date ] [ thread ]