[J3] [BULK] Evaluation of arguments to MERGE
Clune, Thomas L. (GSFC-6101)
thomas.l.clune at nasa.gov
Wed Mar 27 17:40:13 UTC 2024
Belatedly remembering all the discussion about conditional expressions. Just did not connect the dots before hitting send.
So … never mind.
* Tom
From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of Clune, Thomas L. (GSFC-6101) via J3 <j3 at mailman.j3-fortran.org>
Date: Wednesday, March 27, 2024 at 1:32 PM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: Clune, Thomas L. (GSFC-6101) <thomas.l.clune at nasa.gov>
Subject: [BULK] [J3] Evaluation of arguments to MERGE
I have a colleague that is asking about the behavior of MERGE in the program below. The intent of the statement is to avoid divide-by-zero when the FLAG argument is false. This appears to work as intended with most compilers, but under certain flags at least one compiler produces a floating invalid.
I had thought maybe there was special language in the standard about evaluation of the arguments to MERGE, but I did not find any. Therefore, I believe a standard conforming compiler is permitted to evaluate the TSOURCE argument even when FLAG evaluates to false. If I’m wrong about this, please point me to where in the standard that explains this, otherwise I will relay this as a quality-of-implementation concern to my colleague.
program mergetest
implicit none
real*8 :: a,b,c
call random_number(a)
b = 1d0
a = a - a
c = merge(b/a, 0d0, a > 0d0)
write(6,*) c
end program mergetest
Thanks,
· Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240327/b6751884/attachment.htm>
More information about the J3
mailing list