| 5 | import net.optifine.util.MathUtils; |
| 6 | |
| 7 | public class MathHelper |
| 8 | { |
| 9 | public static final float SQRT_2 = sqrt_float(2.0F); |
| 10 | private static final int SIN_BITS = 12; |
| 11 | private static final int SIN_MASK = 4095; |
| 12 | private static final int SIN_COUNT = 4096; |
| 13 | private static final int SIN_COUNT_D4 = 1024; |
| 14 | public static final float PI = MathUtils.roundToFloat(Math.PI); |
| 15 | public static final float PI2 = MathUtils.roundToFloat((Math.PI * 2D)); |
| 16 | public static final float PId2 = MathUtils.roundToFloat((Math.PI / 2D)); |
| 17 | private static final float radToIndex = MathUtils.roundToFloat(651.8986469044033D); |
| 18 | public static final float deg2Rad = MathUtils.roundToFloat(0.017453292519943295D); |
| 19 | private static final float[] SIN_TABLE_FAST = new float[4096]; |
| 20 | public static boolean fastMath = false; |
| 21 | |
| 22 | /** |
| 23 | * A table of sin values computed from 0 (inclusive) to 2*pi (exclusive), with steps of 2*PI / 65536. |
| 24 | */ |
| 25 | private static final float[] SIN_TABLE = new float[65536]; |
| 26 | |
| 27 | /** |
| 28 | * Though it looks like an array, this is really more like a mapping. Key (index of this array) is the upper 5 bits |
| 29 | * of the result of multiplying a 32-bit unsigned integer by the B(2, 5) De Bruijn sequence 0x077CB531. Value |
| 30 | * (value stored in the array) is the unique index (from the right) of the leftmost one-bit in a 32-bit unsigned |
| 31 | * integer that can cause the upper 5 bits to get that value. Used for highly optimized "find the log-base-2 of |
| 32 | * this number" calculations. |
| 33 | */ |
| 34 | private static final int[] multiplyDeBruijnBitPosition; |
| 35 | private static final double field_181163_d; |
| 36 | private static final double[] field_181164_e; |
| 37 | private static final double[] field_181165_f; |
| 38 | |
| 39 | /** |
| 40 | * sin looked up in a table |
| 41 | */ |
| 42 | public static float sin(float p_76126_0_) |
| 43 | { |
| 44 | return fastMath ? SIN_TABLE_FAST[(int)(p_76126_0_ * radToIndex) & 4095] : SIN_TABLE[(int)(p_76126_0_ * 10430.378F) & 65535]; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * cos looked up in the sin table with the appropriate offset |
| 49 | */ |
| 50 | public static float cos(float value) |
| 51 | { |
| 52 | return fastMath ? SIN_TABLE_FAST[(int)(value * radToIndex + 1024.0F) & 4095] : SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535]; |
| 53 | } |
| 54 | |
| 55 | public static float sqrt_float(float value) |
| 56 | { |
| 57 | return (float)Math.sqrt(value); |
| 58 | } |
| 59 | |
| 60 | public static float sqrt_double(double value) |
| 61 | { |
| 62 | return (float)Math.sqrt(value); |
| 63 | } |
| 64 |
nothing calls this directly
no test coverage detected