-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds an expm1 function for complex values. #6539
Conversation
|
||
function expm1(z::Complex) | ||
zr,zi = reim(z) | ||
if isfinite(zr) && !isfinite(zi) return Complex(oftype(zr, NaN), oftype(zi, NaN)) end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reduce the number of comparisons in the common case of finite values, it would be better to check for infinities only once in this case. i.e.
if isfinite(zr)
if isfinite(zi)
....
else
....
end
else # infinite or NaN zr
....
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's true, and it would make it much easier to understand.
I've refactored both |
I'm not sure why travis broke, but it appears to be unrelated to the PR. |
…that cos(x) - 1 = -2*sin(x/2)^2 There is some cancellation error when real(z) ~ imag(z)^2/2 for small z, but otherwise is fairly stable.
I've squashed the commits: is there anything holding this back? |
wi = er*(isfinite(zi) ? sin(zi) : zi) | ||
Complex(wr, wi) | ||
if isnan(zr) | ||
Complex(zr, zi==zero(zi) ? zi : zr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not important but just FYI, zero()
is not necessary in this context (since it's an argument and not a return value).
Adds an expm1 function for complex values.
Partially addresses #3141. It uses the property that
There is some cancellation error when
real(z)
~imag(z)^2/2
for smallz
, but otherwise is fairly stable.I also removed some unnecessary branching conditions from the complex
exp
.