mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
add isPowerOfTwo check
This commit is contained in:
@@ -1296,12 +1296,15 @@ public abstract class PGL {
|
||||
}
|
||||
|
||||
|
||||
protected static boolean isPowerOfTwo(int val) {
|
||||
return (val & (val - 1)) == 0;
|
||||
}
|
||||
|
||||
|
||||
// bit shifting this might be more efficient
|
||||
protected static int nextPowerOfTwo(int val) {
|
||||
int ret = 1;
|
||||
while (ret < val) {
|
||||
ret <<= 1;
|
||||
}
|
||||
while (ret < val) ret <<= 1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user