Operators
min / max / ≅
FullInfix operators that pick the smaller or larger value, and compare with tolerance.
Besides the .min/.max methods, min and max are also infix operators that return the lesser or greater of two values. ≅ (approximately-equal) compares with a small tolerance — useful for floating point.
min and max #
say 5 min 3; say 5 max 3; say 2 min 8 min 5;
Output
3
5
2They chain, so 2 min 8 min 5 is the smallest of the three.
Approximately-equal — ≅ #
≅ (or its ASCII spelling =~=) is true when two numbers are within a small relative tolerance — the right test for floating-point results that should be "equal" but for rounding.
say (0.1 + 0.2) ≅ 0.3; say 1.0 ≅ 1.0000001;
Output
True
FalseNotes #
- The infix
min/maxare handy inline ($x = $lo max $n min $hiclamps$n), while the methods reduce a whole list. ≅matters forNum(floating point); exactRatarithmetic (like0.1 + 0.2) is already exactly0.3, so there==suffices — see Rational literals.- There are matching
minmaxreductions:[min] @xsand[max] @xsfold a list to its extreme with the reduction metaoperator.