abs() implementation is wrongabs() and abs2() got changed from real to complex, but the remaining implementations, like pow(), log(), exp() seems to assume it's real which results in at least unnecessary recursion and may be an infinite one as well. So will need to go back to real.We just discussed it offline with @psychocoderHPC and @BeyondEspresso . Please feel free to add if I missed some other malfunctions in the description.
Luckily, this change was made after 0.5.0 release and so does not affect it.
The abs- and abs2-functions can return a complex number in the form (result,i * 0.0) in order to be more consistent with the other types' implementions. This can also avoid some type-casting in complex-number expressions. However, when reducing to real-valued expressions, such as to avoid recursions in the definition, one has to explicitly call the member-function get_real().
Yes, so there is a choice of either returning a complex, but taking the real part explicitly where we need it. Or changing back to returning real numbers like it used to do before the changes in #3245, or e.g. how it works for std::complex . Which was admittedly not very obvious that it did return a real. I am personally in favor of the latter option, however I think it ultimately does not matter that much, as long as we are consistent.
@BeyondEspresso @gerompampastrumf This might explain some of the discrepancies observed in #3366.
@sbastrakov great catch :+1:
@sbastrakov Only that it was the other way round (as it is still in the current master-branch): Before the changes #3245 the abs-function returned a complex with the result in the real part. There were two main reasons for this decision. 1) The abs-function is the basis of several other complex function implementations, especially sqrt(), pow() and log(), so that a complex return-type for abs() avoids immediate back-conversion to a complex in these functions. 2) The implementation should mimick the behavior of std::complex.
For these reasons, the preferred choice is a complex return type.