10000 Scout/java 5 features by winfriedgerlach · Pull Request #2106 · bcgit/bc-java · GitHub
[go: up one dir, main page]

Skip to content

Scout/java 5 features #2106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid deprecated BigDecimal.ROUND_HALF_EVEN
  • Loading branch information
winfriedgerlach committed Jun 16, 2025
commit 34389fbabd9863f18bff5144fb140be79ad73c28
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.bouncycastle.pqc.legacy.math.ntru.polynomial;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
* A polynomial with {@link BigDecimal} coefficients.
Expand Down Expand Up @@ -214,7 +215,7 @@ public BigIntPolynomial round()
BigIntPolynomial p = new BigIntPolynomial(N);
for (int i = 0; i < N; i++)
{
p.coeffs[i] = coeffs[i].setScale(0, BigDecimal.ROUND_HALF_EVEN).toBigInteger();
p.coeffs[i] = coeffs[i].setScale(0, RoundingMode.HALF_EVEN).toBigInteger();
}
return p;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -284,14 +285,14 @@ public BigDecimalPolynomial div(BigDecimal divisor, int decimalPlaces)
BigInteger max = maxCoeffAbs();
int coeffLength = (int)(max.bitLength() * LOG_10_2) + 1;
// factor = 1/divisor
BigDecimal factor = Constants.BIGDEC_ONE.divide(divisor, coeffLength + decimalPlaces + 1, BigDecimal.ROUND_HALF_EVEN);
BigDecimal factor = Constants.BIGDEC_ONE.divide(divisor, coeffLength + decimalPlaces + 1, RoundingMode.HALF_EVEN);

// multiply each coefficient by factor
BigDecimalPolynomial p = new BigDecimalPolynomial(coeffs.length);
for (int i = 0; i < coeffs.length; i++)
// multiply, then truncate after decimalPlaces so subsequent operations aren't slowed down
{
p.coeffs[i] = new BigDecimal(coeffs[i]).multiply(factor).setScale(decimalPlaces, BigDecimal.ROUND_HALF_EVEN);
p.coeffs[i] = new BigDecimal(coeffs[i]).multiply(factor).setScale(decimalPlaces, RoundingMode.HALF_EVEN);
}

return p;
Expand Down
0