BIS fnc clamp: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(created page)
 
(Add performance comparison)
 
(24 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Function|= Comments
{{RV|type=function


| arma3 |Game name=
|game1= arma3
|version1= 1.00


|1.00|Game version=
|gr1= Math


<!---|arg= local |Multiplayer Arguments=--->
|descr= Clamps provided value within min..max range.
{{Feature|informative|This function is for readability; for performance, directly use [[min]] and [[max]].}}


<!---|eff= local |Multiplayer Effects=--->
|s1= [value, min, max] call [[BIS_fnc_clamp]]


| <pre>/*
|p1= value: [[Number]] - value to be clamped
Author:
Nelson Duarte
Description:
Clamps scalar between min / max
Parameters:
_this: ARRAY
0: SCALAR - The value to clamp
1: SCALAR - Min value
2: SCALAR - Max value
Returns:
SCALAR - Clamped value
*/</pre>{{Informative|Placeholder description extracted from the function header by [[BIS_fnc_exportFunctionsToWiki]]}} |Description=


|[] call [[BIS_fnc_clamp]]|Syntax=
|p2= min: [[Number]] - (Optional, default 0) lower limit


|p1= parameter: Datatype - (Optional, default defValue) description |Parameter 1=
|p3= max: [[Number]] - (Optional, default 0) upper limit


|Datatype - description|Return value=
|r1= [[Number]] - the clamped value


|x1= <code></code>|Example 1=
|x1= <sqf notrim>
[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
</sqf>


| |See also=
|x2= <sqf>
[5, 0, 10] call BIS_fnc_clamp; // 0.0098 ms
0 max 5 min 10; // 0.0011 ms - about 10x faster
</sqf>
 
|seealso= [[min]] [[max]]
}}
}}
[[Category:Function Group: Math|{{uc:clamp}}]]
[[Category:Functions|{{uc:clamp}}]]
[[Category:{{Name|arma3}}: Functions|{{uc:clamp}}]]

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