From a5eaebd622185092566ec364350d1e916324b270 Mon Sep 17 00:00:00 2001 From: Colby Klein Date: Wed, 1 Apr 2015 01:29:45 -0700 Subject: [PATCH] Add utils.is_pot(n) to check for power-of-two. --- modules/utils.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/utils.lua b/modules/utils.lua index b3f8ef7..91cc57c 100644 --- a/modules/utils.lua +++ b/modules/utils.lua @@ -23,4 +23,10 @@ function utils.wrap(v, n) return v % n end +-- from undef: https://love2d.org/forums/viewtopic.php?p=182219#p182219 +-- check if a number is a power-of-two +function utils.is_pot(n) + return 0.5 == (math.frexp(n)) +end + return utils