The funny error "HOW DID I GET HERE" is a logic mistake where we
didn't handle the case where y = 0 and |x| <= 1. From the formula in
the comment we have imagpart(atanh(z))=1/2*(arg(1+x) - arg(1-x)). The
original code only handled |x| > 1, but clearly the formula is 0 if
|x| <= 1.
Replace the call to `error` with a bigfloat 0.
Manually tested the error case and we don't get an error. The answer
matches what `atanh(- 3.378259464834472b-1)` returns in the repl.
Previously we used a messy method that used meval to call atan.
Instead, use the simple relationship that atan(z) = -%i*atanh(%i*z),
and we have a nice algorithm for atanh. The old meval method ended up
calling risplit many times for basically no reason.
The previous setting for the number of terms caused some tests to fail
because the results changed. Increase the limit so that we're more
likely to stop because oans and ans are the same.
Fix #4298: Limit the number of terms in the atan sum
In fpatan, for the case |x| <= 1/2, we use a Taylor series to compute
atan. The criteria for termination is if the previous sum equals the
current sum. This happens when the additional term is so small that
it doesn't contribute anymore. But I think round-off causes the
previous sum and current sum to alternate so they're never equal.
To fix this, compute a rough estimate of the number of terms needed so
that the relative error between the term and x is less than a
tolerance (2^(-fpprec)). With this change, the series then terminates
because we reach the limit of the number of terms.
For the test case, we want the atan of -7.7037b-34. The last term
computed is 9.888b-1756, which is way smaller than needed, but at
least we terminate the loop instead of looping forever.