-
-
Notifications
You must be signed in to change notification settings - Fork 739
Fix Issue 11787 - std.complex should have a separate Imaginary type. #1797
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
Conversation
The rationale for a separate imaginary type has been laid out in Kahan & Thomas, "Augmenting a programming language with complex arithmetic", http://www.eecs.berkeley.edu/Pubs/TechRpts/1992/CSD-92-667.pdf In total this patch implements: * The Imaginary type; * imaginary-numeric operations via Imaginary.opBinary, and numeric- imaginary operations via Imaginary.opBinaryRight * complex-imaginary operations via Complex.opBinary, and imaginary- complex operations via Complex.opBinaryRight; * abs and arg implementations to support Imaginary. A broader range of imaginary-supporting functions (e.g. sin, cos, etc.) are not yet implemented; this will be done conditional on acceptance of the general design.
@@ -15,8 +15,8 @@ | |||
module std.complex; | |||
|
|||
|
|||
import std.format, std.math, std.numeric, std.traits; | |||
|
|||
import std.exception, std.format, std.math, std.numeric, std.traits; |
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.
push these down to where they're used :o)
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.
Ah, I see I'm the guinea pig? :-)
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.
From my painful experience it's much easier to do this in the beginning rather than later...
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.
I agree, good to be moving on it already!
@andralex -- thanks for the detailed feedback. The new patches provide partial fixes for the issues raised -- more to follow. Some notes:
I'll follow up later today with patches addressing the |
Aack. I just realized I didn't include a commit for that -- I must have done it, stashed it, forgotten about it. Anyway, the description stands -- |
Looks like similar unittest failures as those encountered with pull request #1740. I'll see if I can fix those. |
OK, status update:
real re = 0.0;
ireal im = 0.0i;
creal z = 0.0 + 0.0i;
writeln(z == re);
writeln(z == im);
writeln(im == re); ... will output three You can overrule me :-) -- but I wanted to make sure that these factors were at least acknowledged before a final decision. |
My understanding is that allowing "A complex number with a 0.0 real part is often a complex number with a real part so small, it cannot be represented with the floating point underlying that number. In contrast, an That said, it's sensible to allow comparison between a number with no real part and one with a really small real part. I'm deferring this to @donc and others who know more about complex numbers. Since Don has been silent as of late he may be vacationing so let's let this marinate for a short while. Please ping when you see him around. |
@andralex If the built-in complex supports it, so should the library type. Note also that |
I'd say that the rationale for introducing an Agree that we should wait for @donc -- I'm keen to get his feedback, even if it turns out to be "Take this monstrosity away!!" ;-) One point he raised on the mailing list was that it might be possible to do without an imaginary type per se and just have a representation of i. I've been considering that that, but it's not obvious to me how to do it in a "nice" way (or what symbol to use if we do that). |
Imaginary is the counterpart to the "natural" doubles. If "Complex == double" is legal, then so should "Complex == Imaginary". Your argument can be written the other way: I think not having "Complex == Imaginary" would just be inconsistent. |
ping |
IIRC we were basically waiting for feedback. Sorry for not pushing more about that. |
Yea, I should stop dropping subtle hints and nudge him properly ;-) |
ping |
Merge conflicts: rebase please. |
I have talked with @WebDrake , he is unlikely to have any time to get to Phobos hacking soon. Will close his pull requests for now, he will reopen them when ready. |
The rationale for a separate imaginary type has been laid out in Kahan & Thomas, "Augmenting a programming language with complex arithmetic", http://www.eecs.berkeley.edu/Pubs/TechRpts/1992/CSD-92-667.pdf
In total this patch implements:
A broader range of imaginary-supporting functions (e.g. sin, cos, etc.) are not yet implemented; this will be done conditional on acceptance of the general design.
Issue report: https://d.puremagic.com/issues/show_bug.cgi?id=11787