-
Notifications
You must be signed in to change notification settings - Fork 147
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
Implement arithmetic with real for complex #125
Conversation
Following the code that was already written, I have added the forwarding of value-value, value-reference, and reference-value implementations to the corresponding reference-reference implementations. |
Why does this need to explicitly impl primitives? Shouldn't we do this for any generic T? Like:
I do want that comment showing the intended math, even for simple cases like this one. Then repeat this for swapped order, of course, and I think all the forwarding can be extended in the existing macros. How does that sound? |
Thanks for the feedback, Josh! The operations wherein real numbers are on the right-hand side are implemented for any T, and your example is one of such cases (what you wrote is exactly what I have). However, the same generality can’t be attained when working from the left-hand side. That is why I implemented them for concrete types. If you know how to do this for generic types, please let me know. I agree about explanatory comments. Regarding macros, the above from-the-left-side problem made macros quite dissimilar, and I thought that a separate set of macros would be better for understanding. In any case, I can surely try to extend and reuse the macros that are already there. Please let me know what you think. Thanks. |
Argh, sorry - I didn't fully understand what you were doing, and didn't try the complete expansion myself. Now I see it falls afoul of RFC 1023, although I think we're not actually in danger of the sort of orphans that is protecting against. Hmm... This works, but I don't really like it:
Alternatively |
To your original question about implementing subsets of primitives -- I would include unsigned types for e.g. "a - (b + i c) -> (a - b) + i (0 - c)", where the explicit 0 makes it subtraction instead of unary negation. If a>=b and c==0, this will be fine. For any of these real ops, we should get the exact same result as if we'd converted to Alternatively to all of this, we could just @hauleth any thoughts here? |
I’ve implemented Do you still think I should try to reuse |
I’m also a bit concerned with the impact of this forwarding business on performance. I have a very vague idea of what the compiler is doing under the hood, but I hope you carefully considered this when opting for forwarding everything to reference-reference implementations. |
I think that we should implement just |
I would implement I think reusing the forwarding macros makes things easier only if we stick to fully generic implementations. If we keep the special primitive treatment, then special macros are needed. Can you elaborate your performance concern of forwarding? |
I’ve changed the implementations of I also like that the fully complex implementations are reused. It eliminates the inconsistency of implementations that you brought up previously. Regarding performance, I think the most common scenario is that one works with numbers by value, not by reference. In such cases, the forwarding is always exercised, and it appears as an extra function call, which introduces some undesired overhead. Of course, there is inlining, which is supposed to take case of that. I just hope that this functionality works as it is supposed to. |
Given that |
The reason I forward everything to reference-reference implementations is that I followed the code that was already there (in |
Right, I meant forwarding to value-value is probably better for everything in |
I’ve switched to forwarding to value-value implementations. |
@homu r+ |
📌 Commit b57e4a4 has been approved by |
Implement arithmetic with real for complex Hello, It might be handy to be able to perform basic arithmetic operations in expressions mixing complex numbers and numeric primitives; see #116. I would be grateful for any feedback, especially regarding the subsets of primitives for which certain operations are implemented. Regards, Ivan
☀️ Test successful - status |
Hello,
It might be handy to be able to perform basic arithmetic operations in expressions mixing complex numbers and numeric primitives; see #116. I would be grateful for any feedback, especially regarding the subsets of primitives for which certain operations are implemented.
Regards,
Ivan