ShopChest/src/main/java/de/epiceric/shopchest/utils/FastMath.java
MineTheCube 3b9d26c079 Few improvements (#135)
* Fix: Few improvements

* Few improvements

* Hologram/item can wait after shop creation

* Compare worlds using their name

* Fix holograms display

* Changed version to 1.12.4

* Display shop after creation

* Fix requested changed

* Improve performance for simple hologram conditions
2017-08-10 17:02:24 +02:00

43 lines
1.2 KiB
Java

package de.epiceric.shopchest.utils;
public class FastMath {
/**
* Fast sqrt, 1.57% precision
*
* @param n value to calculate square root from
* @return the square root of n
*/
public static double sqrt(double n) {
return n * Double.longBitsToDouble(6910470738111508698L - (Double.doubleToRawLongBits(n) >> 1));
}
/**
* Fast acos, 2.9% precision
*
* @param n value to calculate arc cosine from
* @return the arc cosine of n
*/
public static double acos(double n) {
int v = (int) (n * MULTIPLIER + OFFSET);
while (v > PRECISION) v -= PRECISION;
while (v < 0) v += PRECISION;
return acos[v];
}
// Below is lookup table generation
// It is only executed once at initialization
private static final int PRECISION = 512;
private static final double MULTIPLIER = PRECISION / 2D;
private static final double OFFSET = MULTIPLIER + 0.5D; // + 0.5 as cast truncate and don't round
private static final double[] acos = new double[PRECISION + 1];
static {
for (int i = 0; i <= PRECISION; i++) {
acos[i] = Math.acos(i * (2D / PRECISION) - 1);
}
}
}