All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jtransc.util.JTranscMath Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.

There is a newer version: 0.6.8
Show newest version
package com.jtransc.util;

public class JTranscMath {
	static public int clamp(int v, int min, int max) {
		return Math.min(Math.max(v, min), max);
	}

	public static int roundUpToPowerOfTwo(int i) {
		i--; // If input is a power of two, shift its high-order bit right.

		// "Smear" the high-order bit all the way to the right.
		i |= i >>>  1;
		i |= i >>>  2;
		i |= i >>>  4;
		i |= i >>>  8;
		i |= i >>> 16;

		return i + 1;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy