CLAMP: Difference between revisions
Jump to navigation
Jump to search
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..." |
No edit summary |
||
Line 4: | Line 4: | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: {{Parameter|clamped | : {{Parameter|clamped}} = [[_CLAMP]]({{Parameter|value}}, {{Parameter|minVal}}, {{Parameter|maxVal}}) | ||
Line 11: | Line 11: | ||
* {{Parameter|minVal}} is the minimum range bondary, any integer or floating point type is supported. | * {{Parameter|minVal}} is the minimum range bondary, any integer or floating point type is supported. | ||
* {{Parameter|maxVal}} is the maximum range bondary, any integer or floating point type is supported. | * {{Parameter|maxVal}} is the maximum range bondary, any integer or floating point type is supported. | ||
* {{Parameter|clamped | * {{Parameter|clamped}} is the clamped number. The [[Variable Types|type]] depends on the returned value and will be a best fit without losing precision. | ||
Latest revision as of 16:24, 27 May 2025
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. The type depends on the returned value and will be a best fit without losing precision.
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
-
none
-
v4.0.0
-
yes
-
yes
-
yes
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