bool(3f) - [M_sets::LOGICAL] returns One if expression is TRUE, else returns Zero. (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
pure elemental integer function bool(expr)
logical,intent(in) :: expr or character(len=:)intent(in) :: expr or integer|real|complex(in) :: expr
bool(3f) returns an integer 1 given a true logical expression.
expr A logical expression. If any other intrinsic type a blank string is TRUE as well as 0. 0.0, and (0.0,0.0). Non-zero numeric values and non-blank or non-null strings are FALSE.
The result is a default INTEGER value of 1 if the expression is TRUE, and a 0 otherwise.
Sample usage:
program demo_bool use M_sets, only: bool implicit none write (*, *) is 10 < 20 ?, bool(10 < 20) write (*, *) elemental, bool([2 > 1, 3 == 4, 10 < 5, 100 > 50]) if (sum(bool([2 > 1, 3 == 4, 10 < 5, 100 > 50])) >= 2) then write (*, *) two or more are true endif end program demo_boolResults:
> is 10 < 20 ? 1 > elemental 1 0 0 1 > two or more are true
John S. Urban
CC0-1.0
Nemo Release 3.1 | bool (3) | February 23, 2025 |