-
Notifications
You must be signed in to change notification settings - Fork 14
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
new intrinsic absq()
function for computing squared-absolute value of complex, real, and integer values
#312
Comments
Why would this need to be intrinsic? Can't you define this as an elemental generic? |
We could ask the same question about other existing intrinsics, like
For now, I am stuck with option 4. |
Would this be a good fit for stdlib? |
F'2023 is done. You won't get anything new, including your |
It would be an excellent addition to stdlib if we ensure the compilers inline all usage. Alternatively, could stdlib define an FPP |
Why cannot a compiler optimizer automatically optimize |
A frequent type-agnostic calculation is
abs(x)**2
wherex
iscomplex
orreal
(orinteger
).While the above expression is generic, it involves a costly but, more importantly, unnecessary square-root operation for values of type
complex
.The current community solution is to define a preprocessor macro that properly and efficiently computes the result for arguments of various types. This can be avoided by adding a new intrinsic function
absq(x)
that returns,x**2
ifx
isreal
orinteger
.x%re**2 + x%im**2
ifx
iscomplex
.The text was updated successfully, but these errors were encountered: