Tag: arithmeticexception

BigDecimal下溢

我试图用Java渲染一个名为“Lorenz Attractor”的分形图。 因为double不起作用(值超出范围),所以我决定选择BigDecimals。 经过38次迭代后,我的代码崩溃,它让我得到一个ArithmeticException(Underflow)。 下面是一些代码: BigDecimal xnew = this.x.add(this.hBig.multiply(BigDecimal.TEN).multiply(this.x.add(this.y.negate()))); //This is the line that crashes BigDecimal ynew = this.y.add(this.hBig.multiply(this.x.negate().multiply(this.z)).add(ZWENTYEIGHT.multiply(this.x.add(this.y.negate())))); BigDecimal znew = this.z.add(this.hBig.multiply(this.x.multiply(this.y).add(FRAC.multiply(this.z).negate()))); this.x = xnew; this.y = ynew; this.z = znew; System.out.println(“X=”+this.x); System.out.println(“Y=”+this.y); System.out.println(“Z=”+this.z); System.out.println(“———-“); 这是我得到的输出 。 我可以做任何反对吗? 对不起,如果代码不是很好。 我也可以提供一些关于应该怎么做的伪代码,告诉我你是否需要它。 编辑:这是分裂的第二行: BigDecimal temp = ZWENTYEIGHT.multiply(this.x.add(this.y.negate())); BigDecimal temp2 = this.x.negate().multiply(this.z); BigDecimal temp3 = this.hBig.multiply(temp2); //This […]

使用此椭圆曲线点乘法计算的点不在曲线上,并且此类带来算术exception

我使用标准投影坐标得到了我的点乘法误差。 我不知道我错过了什么,但是乘法点不在曲线上,有时它会输出类似算术exception的东西:整数不可逆。 public class ECPointArthimetic { EllipticCurve ec; private BigInteger x; private BigInteger y; private BigInteger z; private BigInteger zinv; private BigInteger one = BigInteger.ONE; private BigInteger zero = BigInteger.ZERO; private boolean infinity; public ECPointArthimetic(EllipticCurve ec, BigInteger x, BigInteger y, BigInteger z) { this.ec = ec; this.x = x; this.y = y; // Projective coordinates: […]

项目Euler#3超出整数范围java

该代码应该回馈最大的素数。 有关此任务的更多信息,请访问: https : //projecteuler.net/problem=3 int checkFactors(double na) { long n = (long) na; int biggestPrimeFactor = 0; for (int i = 1; i biggestPrimeFactor) biggestPrimeFactor = i; return biggestPrimeFactor; } boolean isPrimeFactor(int n) { int length= 0; for (int i = n; i > 0; i–) if (n % i == 0) length++; if […]

Java除以零不会抛出ArithmeticException – 为什么?

为什么这段代码不会抛出ArithmeticException ? 看一看: public class NewClass { public static void main(String[] args) { // TODO code application logic here double tab[] = {1.2, 3.4, 0.0, 5.6}; try { for (int i = 0; i < tab.length; i++) { tab[i] = 1.0 / tab[i]; } } catch (ArithmeticException ae) { System.out.println("ArithmeticException occured!"); } } } 我不知道!