j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
177 stars 15 forks source link

Extend the NORM2 intrinsic function to COMPLEX argument #340

Open nncarlson opened 4 days ago

nncarlson commented 4 days ago

It would be useful to extend the norm2 intrinsic function to complex arrays, so that norm2(z) returns sqrt(sum(conjg(z)* z)). Note that dot_product already appropriately handles the case of complex arrays so that in the case of a rank-1 array this is equivalent to sqrt(dot_product(z,z)).

This is such an obvious extension of norm2 that is is puzzling why it wasn't included in the first place. There must be implementation difficulties (e.g., the standard recommendation "that the processor compute the result without undue overflow or underflow") for it to have been omitted.

Edit: sqrt(sum(conjg(z),z)) --> sqrt(sum(conjg(z)*z))

klausler commented 4 days ago

Did you mean sqrt(sum(conjg(z) * z))?

nncarlson commented 4 days ago

Did you mean sqrt(sum(conjg(z) * z))?

Um, yeah... That was dumb of me.