File tree Expand file tree Collapse file tree 3 files changed +42
-8
lines changed
common/src/main/java/net/caffeinemc/mods/lithium
fabric/src/test/java/math/sine_lut Expand file tree Collapse file tree 3 files changed +42
-8
lines changed Original file line number Diff line number Diff line change @@ -54,13 +54,13 @@ public static void init() {
5454 }
5555
5656 // [VanillaCopy] MathHelper#sin(float)
57- public static float sin (float f ) {
58- return lookup ((int ) (f * 10430.378f ) & 0xFFFF );
57+ public static float sin (double d ) {
58+ return lookup ((int ) (d * 10430.378350470453 ) & 0xFFFF );
5959 }
6060
6161 // [VanillaCopy] MathHelper#cos(float)
62- public static float cos (float f ) {
63- return lookup ((int ) (f * 10430.378f + 16384.0f ) & 0xFFFF );
62+ public static float cos (double d ) {
63+ return lookup ((int ) (d * 10430.378350470453 + 16384.0 ) & 0xFFFF );
6464 }
6565
6666 private static float lookup (int index ) {
Original file line number Diff line number Diff line change @@ -25,16 +25,16 @@ private static void onClassInit(CallbackInfo ci) {
2525 * @reason use an optimized implementation
2626 */
2727 @ Overwrite
28- public static float sin (float f ) {
29- return CompactSineLUT .sin (f );
28+ public static float sin (double d ) {
29+ return CompactSineLUT .sin (d );
3030 }
3131
3232 /**
3333 * @author jellysquid3
3434 * @reason use an optimized implementation
3535 */
3636 @ Overwrite
37- public static float cos (float f ) {
38- return CompactSineLUT .cos (f );
37+ public static float cos (double d ) {
38+ return CompactSineLUT .cos (d );
3939 }
4040}
Original file line number Diff line number Diff line change 1+ package math .sine_lut ;
2+
3+
4+ import net .caffeinemc .mods .lithium .common .util .math .CompactSineLUT ;
5+ import net .minecraft .util .Mth ;
6+ import org .junit .jupiter .api .Assertions ;
7+ import org .junit .jupiter .api .Test ;
8+
9+ import java .util .Random ;
10+
11+ public class CompactSineLUTTest {
12+
13+ @ Test
14+ public void testSin () {
15+ Random rand = new Random ();
16+ for (int i = 0 ; i < 1_000_000 ; i ++) {
17+ double d = rand .nextDouble () * 1000 ;
18+ float lithiumSin = CompactSineLUT .sin (d );
19+ float vanillaSin = Mth .sin (d );//TODO: Make sure to only run this without applying mixins
20+ Assertions .assertEquals (lithiumSin , vanillaSin );
21+ }
22+ }
23+
24+ @ Test
25+ public void testCos () {
26+ Random rand = new Random ();
27+ for (int i = 0 ; i < 1_000_000 ; i ++) {
28+ double d = rand .nextDouble () * 1000 ;
29+ float lithiumCos = CompactSineLUT .cos (d );
30+ float vanillaCos = Mth .cos (d ); //TODO: Make sure to only run this without applying mixins
31+ Assertions .assertEquals (lithiumCos , vanillaCos );
32+ }
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments