Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Is a value between two other values?

between?: func [
    value bound-1 bound-2
    /exclusive
    /local low-bound high-bound
][
    set [low-bound high-bound] sort reduce [bound-1 bound-2]
    either exclusive [
        all [(value > low-bound) (value < high-bound)]
    ][
        ;-- Inclusive comparison
        all [(value >= low-bound) (value <= high-bound)]
    ]
]

limit - limit a value between boundary values

limit: func [
    "Make sure val falls between lower and upper bounds, inclusive"
    val lower upper
][
    max min val upper lower
]

limit function - limit a value within bounds

limit: func [
    "Make sure val falls between lower and upper bounds, inclusive"
    val lower upper
][
    max min val upper lower
]
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS