Java 中是否有任何用于平方根而不是 BigDecimal 的库?
最佳答案
JScience v4.3.1有一个 Real
似乎相当于 BigDecimal
的类,这可能会对您有所帮助。使用示例:
// The Square Root of Two, to 30 digits
// According to "The Square Root of Two, to 5 million digits."
// Source: http://www.gutenberg.org/files/129/129.txt
System.out.println("1.41421356237309504880168872420");
// Using JScience with 50 digits precision
Real.setExactPrecision(50);
System.out.println(Real.valueOf(2).sqrt());
// Using default java implementation
System.out.println(Math.sqrt(2));
> 1.41421356237309504880168872420
> 1.414213562373095048801689
> 1.4142135623730951
编辑:更新了代码和链接以反射(reflect)当时的当前版本 (v4.3.1)。基于@ile 和@Tomasz 的评论,谢谢。
关于java - 是否有 BigDecimal 上的 Square Root 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1384919/