marcomaggi / vicare

A native compiler for Scheme compliant with R6RS
http://marcomaggi.github.com/vicare.html
Other
200 stars 34 forks source link

atan on small imaginary numbers loses precision #30

Closed barak closed 13 years ago

barak commented 13 years ago

for small x, (atan x) is approximately x, since (atan 0) is 0 and the derivative of atan at 0 is 1. However for small imaginary arguments, there is a loss of precision causing bogus low digits and, for small enough arguments, rounding down to zero.

vicare> (atan 1e-20i) 0.0+0.0i

This is caused by (log (+ 1 e)) when e is small. The "right" fix is to use the C function log1p, which means an interface to that must be created, should probably be exposed at the user level, etc.

marcomaggi commented 13 years ago

Added fllog1p and flexpm1 to (vicare) and (ikarus).

barak commented 13 years ago

cool.

(not i need to tweak def of atan to take advantage of it. will give it a shot. looks a little more subtle than i thought. might be easier to directly call the C math library complex routine catan(3) in order to fix this particular issue ... not that I've tested that routine for this particular issue ...)