bound(3f) - [M_math] constrain a value to a range
Synopsis
Description
Options
Returns
Example
elemental function bound(bottom, middle, top)
ALLOWED_TYPE, intent(in) :: bottom, middle, top ALLOWED_TYPE :: boundwhere 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=>real64All input values must be of the same KIND.
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.
bottom The minimum value to return. middle The value to constrain to the range BOTTOM to TOP. top The maximum value to return.
bound The value of MIDDLE is returned except BOTTOM is returned when MIDDLE < BOTTOM and the value of TOP is returned when MIDDLE > TOP.
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_boundResults: 3 1 10
1 1 6 10 10 5.50000000
Nemo Release 3.1 | bound (3) | February 23, 2025 |