mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-26 07:34:35 +00:00
Note about branchless or abs-based mathx.sign
This commit is contained in:
parent
fe135c533b
commit
a2c7800290
@ -46,6 +46,7 @@ function mathx.to_precision(v, decimal_points)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--0, 1, -1 sign of a scalar
|
--0, 1, -1 sign of a scalar
|
||||||
|
--todo: investigate if a branchless or `/abs` approach is faster in general case
|
||||||
function mathx.sign(v)
|
function mathx.sign(v)
|
||||||
if v < 0 then return -1 end
|
if v < 0 then return -1 end
|
||||||
if v > 0 then return 1 end
|
if v > 0 then return 1 end
|
||||||
|
Loading…
Reference in New Issue
Block a user