BIS fnc clamp: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Function " to "{{RV|type=function ")
(Add performance comparison)
 
(17 intermediate revisions by the same user not shown)
Line 2: Line 2:


|game1= arma3
|game1= arma3
|version1= 1.00
|version1= 1.00


|gr1 = Math
|gr1= Math


|descr= Clamps provided value within min..max range.
|descr= Clamps provided value within min..max range.
{{Feature|informative|This function is for readability; for performance, directly use [[min]] and [[max]].}}


|s1= [value, min, max] call [[BIS_fnc_clamp]]
|s1= [value, min, max] call [[BIS_fnc_clamp]]


|p1= value: [[Number]] - value to be clamped
|p1= value: [[Number]] - value to be clamped
|p2= min: [[Number]] - (Optional, default 0) lower limit
|p2= min: [[Number]] - (Optional, default 0) lower limit
|p3= max: [[Number]] - (Optional, default 0) upper limit
|p3= max: [[Number]] - (Optional, default 0) upper limit


|r1= [[Number]] - the clamped value
|r1= [[Number]] - the clamped value


|x1= <code> [5, 0, 10] [[call]] [[BIS_fnc_clamp]]; {{cc|returns 5}}
|x1= <sqf notrim>
  [0, 0, 10] [[call]] [[BIS_fnc_clamp]]; {{cc|returns 0}}
[5, 0, 10] call BIS_fnc_clamp; // returns 5
[10, 0, 10] [[call]] [[BIS_fnc_clamp]]; {{cc|returns 10}}
  [0, 0, 10] call BIS_fnc_clamp; // returns 0
[-5, 0, 10] [[call]] [[BIS_fnc_clamp]]; {{cc|returns 0}}
[10, 0, 10] call BIS_fnc_clamp; // returns 10
[15, 0, 10] [[call]] [[BIS_fnc_clamp]]; {{cc|returns 10}}
[-5, 0, 10] call BIS_fnc_clamp; // returns 0
[15, 0, 10] call BIS_fnc_clamp; // returns 10
[5, 10, 3] call BIS_fnc_clamp; // returns 10
</sqf>


[5, '''10''', 3] [[call]] [[BIS_fnc_clamp]]; {{cc|returns 10}}
|x2= <sqf>
</code>
[5, 0, 10] call BIS_fnc_clamp; // 0.0098 ms
0 max 5 min 10; // 0.0011 ms - about 10x faster
</sqf>


|seealso=
|seealso= [[min]] [[max]]
}}
}}

Latest revision as of 16:49, 21 May 2023

Hover & click on the images for description

Description

Description:
Clamps provided value within min..max range.
This function is for readability; for performance, directly use min and max.
Execution:
call
Groups:
Math

Syntax

Syntax:
[value, min, max] call BIS_fnc_clamp
Parameters:
value: Number - value to be clamped
min: Number - (Optional, default 0) lower limit
max: Number - (Optional, default 0) upper limit
Return Value:
Number - the clamped value

Examples

Example 1:
[5, 0, 10] call BIS_fnc_clamp; // returns 5 [0, 0, 10] call BIS_fnc_clamp; // returns 0 [10, 0, 10] call BIS_fnc_clamp; // returns 10 [-5, 0, 10] call BIS_fnc_clamp; // returns 0 [15, 0, 10] call BIS_fnc_clamp; // returns 10 [5, 10, 3] call BIS_fnc_clamp; // returns 10
Example 2:
[5, 0, 10] call BIS_fnc_clamp; // 0.0098 ms 0 max 5 min 10; // 0.0011 ms - about 10x faster

Additional Information

See also:
min max

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note