# max ## Category Arithmetic ## Arity **Binary** — `a max b`. ``` max ``` ## Description Returns the larger of two numbers. If equal, returns that value. Auto-unwraps `shared` values before comparing. ## How It Works Compares two `double` values and returns the greater one. Equivalent to `Math.Max(a, b)`. The host re-registers `max` with shared-value unwrapping. ## Usage ### Clamp lower bound ```sqf _hp = _hp max 0; // never below 0 _damage = (_incoming - _armor) max 0; // no negative damage ``` ### Simple maximum ```sqf _best = _scoreA max _scoreB; _budget = _requested max _minimum; ``` ### Full clamp (with min) ```sqf // Clamp _value between _low and _high _clamped = (_value max _low) min _high; // Example: clamp health to [0, 100] _hp = ((_hp + _heal) max 0) min 100; ``` ### Array reduction (find maximum) ```sqf _findMax = { params ["_arr"]; private _max = _arr select 0; { _max = _max max _x } forEach _arr; _max }; _result = [3, 7, 2, 9] call _findMax; // 9 ``` ## Thread Safety ReadOnly — pure computation, no side effects. Safe from any scheduler. ## See Also - [min](min.md) — smaller of two numbers - [>](greater-than.md) — greater-than comparison - [select](select.md) — array element access