C Library Functions  - bound (3)

NAME

bound(3f) - [M_math] constrain a value to a range

CONTENTS

Synopsis
Description
Options
Returns
Example

SYNOPSIS

elemental function bound(bottom, middle, top)

   ALLOWED_TYPE, intent(in) :: bottom, middle, top
   ALLOWED_TYPE        :: bound

where ALLOWED_TYPE may be REAL or INTEGER of default kind from the set of kinds defined by

    use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64, &
    & real32, real64, real128, dp=>real64

All input values must be of the same KIND.

DESCRIPTION

Constrain a value to the range from BOTTOM to TOP inclusive. The user is responsible for ensuring BOTTOM is less than or equal to TOP.

The results for input values of +-INF and NAN are the same as for the MAX(3f) and MIN(3f) intrinsic functions.

OPTIONS

bottom The minimum value to return.
middle The value to constrain to the range BOTTOM to TOP.
top The maximum value to return.

RETURNS

bound The value of MIDDLE is returned except BOTTOM is returned when MIDDLE < BOTTOM and the value of TOP is returned when MIDDLE > TOP.

EXAMPLE

Sample program

    program demo_bound
    use,intrinsic :: iso_fortran_env, only : &
     & int8, int16, int32, int64, &
     & real32, real64, real128, dp=>real64
    use M_math, only : bound
    implicit none
       write(*, *)bound(1, 3, 10)
       write(*, *)bound(1, -30, 10)
       write(*, *)bound(1, 30, 10)
       write(*, *)bound(1, [-11,0,6,11,22], 10)
       write(*, *)bound(-11.11, 5.5, 9.999)
    end program demo_bound

Results: 3 1 10
1 1 6 10 10 5.50000000


Nemo Release 3.1 bound (3) July 22, 2023
Generated by manServer 1.08 from 04bda8d8-3d04-4aa1-b097-7a8c982c41b2 using man macros.