JuliaLang/julia — pull request #2891 by jiahao (2013-04-19 22:22:02+00:00)
Title: Implements Kahan's versions of elementary complex functions

I've implemented Kahan's versions of elementary complex functions, paying particular attention to behavior near branch cuts.

The behavior of complex elementary functions has come up in recent issues (#2889 #2843 #2845 #2875) and it was probably high time to have implementations of these functions that paid proper attention to branch cut issues.

This commit provides the functions described in the Reference, implementing these algorithms verbatim (except where noted).

- List of functions affected: `sqrt`, `^`, `log`, `asin`, `acos`, `atan`, `tanh`, `asinh`, `acosh`, `atanh`
- Includes also `ssqs` to compute the mod-squared of a complex number scaled by a power of 2 to avoid overflow/underflow. `ssqs` is not exported.
-
Issues
- The `^` function fails tests so is disabled for now.
- The `log` function works only for `Complex{FloatingPoint}`. Explicitly casting `{T<:Integer}Complex{T}` to floating-point `Complex` causes tests to fail.

Ref: [Branch cuts for complex elementary functions](http://people.freebsd.org/~das/kahan86branch.pdf)

Hopefully this is a good starting point to get the complex arithmetic done up properly in Julia.

@alanedelman: "Nobody pays attention to branch cuts even for scalar complex functions, let alone matrix-valued functions"

cc: @ViralBShah @JeffBezanson @simonbyrne @bsxfan @andreasnoackjensen