BigDecimal上有Square Root的库吗? [英] Are there libraries for Square Root over BigDecimal?
本文介绍了BigDecimal上有Square Root的库吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Java中BigDecimal的Square Root是否有任何库?
Are there any libraries for Square Root over BigDecimal in Java?
推荐答案
JScience v4.3.1 有 Real
类似乎相当于 BigDecimal
,这可能对您有所帮助。使用示例:
JScience v4.3.1 has a Real
class which seems to be the equivalent of BigDecimal
and that might help you. An example of usage:
// 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
编辑:更新了代码和链接以反映当前版本当时(v4.3.1)。根据@ile和@Tomasz的评论,谢谢。
Edit: Updated the code and the links to reflect the current version at the time (v4.3.1). Based on @ile an @Tomasz comments, thanks.
这篇关于BigDecimal上有Square Root的库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文