Skip to content

Commit

Permalink
bugfix for multiplication by 0.80 in integer domain
Browse files Browse the repository at this point in the history
  • Loading branch information
xtonik committed Jan 25, 2024
1 parent 6a2ea3b commit a4840c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ private int _resizeAndFindOffsetForAdd(int hash) throws StreamConstraintsExcepti
}

static int multiplyByFourFifths(int number) {
return (int) (number * 1_717_986_919L >>> 33);
return (int) (number * 3_435_973_837L >>> 32);
}

// Helper method for checking if we should simply rehash() before add
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.fasterxml.jackson.core.sym;

import com.fasterxml.jackson.core.BaseTest;
import org.junit.Ignore;
import org.junit.Test;

public class ByteQuadsCanonicalizerTest extends BaseTest {
import static org.junit.Assert.assertEquals;

public class ByteQuadsCanonicalizerTest {
@Test
@Ignore
public void testMultiplyByFourFifths() {
for (long i = 0; i <= Integer.MAX_VALUE; i++) {
int number = (int) i;
int expected = (int) (number * 0.80);
int actual = ByteQuadsCanonicalizer.multiplyByFourFifths(number);
assertEquals(expected, actual, number);
assertEquals("input=" + number, expected, actual);
}
}
}

0 comments on commit a4840c2

Please sign in to comment.