On Sat, 2007-09-01 at 11:23 +0100, Chris Jones wrote: > On Saturday 1 September 2007 9:36:02 am Mogens Kjaer wrote: > > Chris Jones wrote: > > ... > > > > > for the profiler output. atan2 is taking 50% of the time of this method. > > > Not here I don't need that much precision on the result - say +- > > > O(2*pi/100). > > > > Can't you use a Taylor expansion of arctan? > > Talyor expansions are valid when your argument is 'small' i.e. > > sin(x) ~ x > tan(x) ~ x > cos(x) ~ (1-(x)*(x)/2) > > etc. only work when x is small, and the error increases as x does (since the > size of the truncated terms become more important). Yes you can include more > terms but that only allows you to go to large x before the errors explode. > > I'm well aware of these series, and already use them when appropriate. In this > case, I need tan(x) with fixed errors, between 0 and 2pi, the whole range. > > for instance, a really course estimate for atan2(x,y) can be made, by just > comparing the signs of x and y, i.e. if x>0 and y>0, atan2(x,y) is between 0 > and pi/2 ... > > Chris > Hi, Chris, When I need limited precision for such a value (fixed, some limited resolution), I generally implement it with a lookup table. If implemented in assembly, it is about 6 to 10 instructions to retrieve the value, and add a multiply and truncate to get the resolution you need from a floating point result, and an add if you have negative results. This is often faster than even hardware processing for complex values. Regards, Les H -- fedora-list mailing list fedora-list@xxxxxxxxxx To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list