M_overload(3fm) - [M_overload::LOGICAL] returns Zero if expression is FALSE, else returns One.
(LICENSE:PD)
pure elemental integer function zo(expr)
logical,intent(in) :: expr
Returns an integer given a logical expression.
expr A logical expression
The result is a default INTEGER value of 0 if the expression is TRUE,
and a 1 otherwise.
Sample usage:
program demo_zo
use M_overload, only: zo, zo, lt, le, eq, ne, gt, ge
implicit none
write (*, *) zo(10 < 20)
if (sum(zo([1 > 2, 3 == 4, 10 < 5, 100 > 50])) > 2) then
write (*, *) 'two or more are not true'
endif
end program demo_zo
Results:
> 0
> two or more are not true
John S. Urban
Public Domain
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
logical, | intent(in) | :: | expr |
pure elemental integer function zo(expr) ! ident_10="@(#) M_strings zo(3f) logical to integer TRUE results in 0 FALSE results in 1" logical, intent(in) :: expr zo = merge(0, 1, expr) ! Zero and One end function zo