C Library Functions  - bool (3)

NAME

bool(3f) - [M_sets::LOGICAL] returns One if expression is TRUE, else returns Zero. (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

pure elemental integer function bool(expr)

    logical,intent(in) :: expr
      or
    character(len=:)intent(in) :: expr
      or
    integer|real|complex(in) :: expr

DESCRIPTION

bool(3f) returns an integer 1 given a true logical expression.

OPTIONS

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.

RETURNS

The result is a default INTEGER value of 1 if the expression is TRUE, and a 0 otherwise.

EXAMPLES

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_bool

Results:

    > is 10 < 20 ? 1
    > elemental 1 0 0 1
    > two or more are true

AUTHOR

John S. Urban

LICENSE

CC0-1.0


Nemo Release 3.1 bool (3) February 23, 2025
Generated by manServer 1.08 from 156ac484-4687-431f-a298-a183f76ad829 using man macros.