_CLAMP

From QB64 Phoenix Edition Wiki
Revision as of 17:05, 2 December 2024 by RhoSigma (talk | contribs) (Created page with "{{DISPLAYTITLE:_CLAMP}} The '''_CLAMP''' function forces the given numeric value into a specific range, returning either the given value as is, or the closest boundary if the range is exceeded. {{PageSyntax}} : {{Parameter|clamped##}} = _CLAMP({{Parameter|value}}, {{Parameter|minVal}}, {{Parameter|maxVal}}) {{PageParameters}} * {{Parameter|value}} is the number to clamp, any integer or floating point type is supported. * {{Parameter|minVal}} is the minimum range...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The _CLAMP function forces the given numeric value into a specific range, returning either the given value as is, or the closest boundary if the range is exceeded.


Syntax

clamped## = _CLAMP(value, minVal, maxVal)


Parameters

  • value is the number to clamp, any integer or floating point type is supported.
  • minVal is the minimum range bondary, any integer or floating point type is supported.
  • maxVal is the maximum range bondary, any integer or floating point type is supported.
  • clamped## is the clamped number return as _FLOAT type (suffix ##).


Description

  • The function compares the given numeric value with a given minimum and maximum range boundary and returns a value which is not exceeding that range, i.e.:
    • it will return the unmodified value itself, if it fits into the given range.
    • it returns minVal, if value is less than the minimum allowed.
    • it returns maxVal, if value is greater than the minimum allowed.


Availability


Examples

PRINT _CLAMP(123.345, 100, 200) 'value ok, returned as is
PRINT _CLAMP(67.89, 100, 200) 'value < as allowed, return minimum
PRINT _CLAMP(234.5, 100, 200) 'value > as allowed, return maximum
 123.456
 100
 200


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link