gpt4 book ai didi

java - 使用 Java BigDecimal 提高准确性

转载 作者:行者123 更新时间:2023-11-30 07:42:48 24 4
gpt4 key购买 nike

开胃菜

R = new BigDecimal(2.79E+00);
Dxm3d = new BigDecimal(3.99E-04);
Wmd = new BigDecimal(2.39E-03);
x = new BigDecimal(3.2);
t = new BigDecimal(365);

下面是公式

这些值 J263 是代表我的变量的 Excel 选票。

  • J253 值:2,39E-03 是 Wmd
  • J254 值:3,99E-04 是 Dxm3d
  • J 255 值:2,79E00 是 R
  • I259:365 是 t
  • J263 值:3.2 是 x

enter image description here

enter image description here

BigDecimal segundoTermo = (R.multiply(x).subtract(Wmd.multiply(t)).divide(new BigDecimal(2d).multiply(new BigDecimal(Math.sqrt(Dxm3d.multiply(R).multiply(t).doubleValue()))), RoundingMode.HALF_DOWN));
System.out.println("value segundoTermo " + segundoTermo);

返回值

valor do segundo termo pfv:6.31838147917065306052600332590254032941338413886611227745342947009953030493273342105799365116070956364

预期值

6,321092458

最佳答案

我说:

I'm betting the difference you're seeing is due to the Math.sqrt() call which takes a double. You might take a look at JScience and this answer.

但最终使用 JScience 的 FloatingPoint 返回与问题中的 BigDecimal 相同的值:

FloatingPoint R = FloatingPoint.valueOf(2.79E+00);
FloatingPoint Dxm3d = FloatingPoint.valueOf(3.99E-04);
FloatingPoint Wmd = FloatingPoint.valueOf(2.39E-03);
FloatingPoint x = FloatingPoint.valueOf(3.2);
FloatingPoint t = FloatingPoint.valueOf(365);
FloatingPoint segundoTermo = (R.times(x).minus(Wmd.times(t)).divide(FloatingPoint.valueOf(2d).times(((Dxm3d.times(R).times(t)).sqrt()))));
System.out.println("value segundoTermo " + segundoTermo);

输出:

value segundoTermo 0.63188145784374107900E1

您确定期望值正确吗?

关于java - 使用 Java BigDecimal 提高准确性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34424262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com