|
17 | 17 | */
|
18 | 18 | public class SculkMath {
|
19 | 19 |
|
20 |
| - public static long log2(long N) |
21 |
| - { |
| 20 | + private static final float[] trigonometry = new float[Limits.UINT16_MAX + 1]; |
| 21 | + |
| 22 | + static final double M_2PI = Math.PI * 2.0D; |
| 23 | + |
| 24 | + static final double M_PI2 = Math.PI / 2.0D; |
22 | 25 |
|
23 |
| - // calculate log2 N indirectly |
24 |
| - // using log() method |
| 26 | + static { |
| 27 | + int short_max1 = Limits.UINT16_MAX + 1; |
| 28 | + for (int i = 0; i < short_max1; i++) |
| 29 | + trigonometry[i] = (float) Math.sin(i * M_2PI / short_max1); |
| 30 | + } |
| 31 | + |
| 32 | + public static float sqrt(float paramFloat) { |
| 33 | + return (float) Math.sqrt(paramFloat); |
| 34 | + } |
| 35 | + |
| 36 | + public static float sin(float paramFloat) { |
| 37 | + return trigonometry[((int) (paramFloat * 10430.378F) & Limits.UINT16_MAX)]; |
| 38 | + } |
| 39 | + |
| 40 | + public static float cos(float paramFloat) { |
| 41 | + return trigonometry[((int) (paramFloat * 10430.378F + 16384.0F) & Limits.UINT16_MAX)]; |
| 42 | + } |
| 43 | + |
| 44 | + public static float sin(double paramFloat) { |
| 45 | + return trigonometry[((int) (paramFloat * 10430.378F) & Limits.UINT16_MAX)]; |
| 46 | + } |
25 | 47 |
|
| 48 | + public static float cos(double paramFloat) { |
| 49 | + return trigonometry[((int) (paramFloat * 10430.378F + 16384.0F) & Limits.UINT16_MAX)]; |
| 50 | + } |
| 51 | + |
| 52 | + public static long log2(long N) |
| 53 | + { |
26 | 54 | return (long)(Math.log(N) / Math.log(2));
|
27 | 55 | }
|
28 | 56 |
|
29 | 57 | public static int log2(int N)
|
30 | 58 | {
|
| 59 | + return (int)(Math.log(N) / Math.log(2)); |
| 60 | + } |
| 61 | + |
| 62 | + public static int ceil(float value) |
| 63 | + { |
| 64 | + int truncate = (int) value; |
| 65 | + return value > truncate ? truncate + 1 : truncate; |
| 66 | + } |
| 67 | + public static int clamp(int check, int min, int max) { |
| 68 | + return check > max ? max : (Math.max(check, min)); |
| 69 | + } |
31 | 70 |
|
32 |
| - // calculate log2 N indirectly |
33 |
| - // using log() method |
| 71 | + public static double denormalizeClamp(double lowerBnd, double upperBnd, double slide) { |
| 72 | + return slide < 0.0D ? lowerBnd : (slide > 1.0D ? upperBnd : lowerBnd + (upperBnd - lowerBnd) * slide); |
| 73 | + } |
34 | 74 |
|
35 |
| - return (int)(Math.log(N) / Math.log(2)); |
| 75 | + public static float denormalizeClamp(float lowerBnd, float upperBnd, float slide) { |
| 76 | + return slide < 0.0f ? lowerBnd : (slide > 1.0f ? upperBnd : lowerBnd + (upperBnd - lowerBnd) * slide); |
36 | 77 | }
|
37 | 78 | }
|
0 commit comments