Site Tools
Sidebar
User's Manual
t2:clamp
clamp
clamp - Restricts a value to be within a specified range
Description
int32 clamp(int32 num, int32 lo, int32 hi);
fix32 clamp(fix32 num, fix32 lo, fix32 hi);
Computes the value of num clamped to the range defined by lo and hi.
Parameters
- num: The value to clamp.
- lo: The minimum value. If num is less than lo, lo will be returned.
- hi: The maximum value. If num is greater than hi, hi will be returned.
Return Value
The clamped value of num.
Examples
Example #1 clamp() example
init { printf("%d", clamp(55, 1, 10)); // 10 printf("%d", clamp(-15, 1, 10)); // 1 printf("%.1f", clamp(4.5, 1.0, 10.0)); // 4.5 }
See Also
t2/clamp.txt · Last modified: 2017/01/22 05:23 by J2Kbr