Explorar o código

added isPowerOfTwo

Alexander Rose %!s(int64=6) %!d(string=hai) anos
pai
achega
5693559746
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      src/mol-math/misc.ts

+ 5 - 1
src/mol-math/misc.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -10,4 +10,8 @@ export function degToRad (deg: number) {
 
 export function radToDeg (rad: number) {
     return rad * 57.29578  // rad * 180 / Math.PI
+}
+
+export function isPowerOfTwo (x: number) {
+    return (x !== 0) && (x & (x - 1)) === 0
 }