栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

使用任意精度的高级 Java BigDecimal 数学函数(pow、sqrt、log、sin...)。

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用任意精度的高级 Java BigDecimal  数学函数(pow、sqrt、log、sin...)。

使用 BigDecimalMath 类输出Java BigDecimal任意精度

big-math 源码地址: https://github.com/eobermuhlner/big-math

在 Maven 项目中引入 : big-math

    ch.obermuhlner
    big-math
    2.3.0
BigDecimalMath 类为以下方面提供了高效且准确的实现:

log(BigDecimal, MathContext) exp(BigDecimal, MathContext) pow(BigDecimal, BigDecimal, MathContext) calculates x^y sqrt(BigDecimal, MathContext) root(BigDecimal, BigDecimal, MathContext) calculates the n'th root of x sin(BigDecimal, MathContext) cos(BigDecimal, MathContext) tan(BigDecimal, MathContext) asin(BigDecimal, MathContext) acos(BigDecimal, MathContext) atan(BigDecimal, MathContext) atan2(BigDecimal, BigDecimal, MathContext) sinh(BigDecimal, MathContext) cosh(BigDecimal, MathContext) tanh(BigDecimal, MathContext) asinh(BigDecimal, MathContext) acosh(BigDecimal, MathContext) atanh(BigDecimal, MathContext) pow(BigDecimal, long, MathContext) calculates x^y for long y factorial(int) calculates n! bernoulli(int) calculates Bernoulli numbers pi(MathContext) calculates pi to an arbitrary precision e(MathContext) calculates e to an arbitrary precision toBigDecimal(String) creates a BigDecimal from string representation (faster than BigDecimal(String) ) mantissa(BigDecimal) extracts the mantissa from a BigDecimal (mantissa * 10^exponent) exponent(BigDecimal) extracts the exponent from a BigDecimal (mantissa * 10^exponent) integralPart(BigDecimal) extracts the integral part from a BigDecimal (everything before the decimal point) fractionalPart(BigDecimal) extracts the fractional part from a BigDecimal (everything after the decimal point) isIntValue(BigDecimal) checks whether the BigDecimal can be represented as an int value isDoublevalue(BigDecimal) checks whether the BigDecimal can be represented as a double value roundWithTrailingZeroes(BigDecimal, MathContext) rounds a BigDecimal to an arbitrary precision with trailing zeroes. 实例

BigDecimal 幂运算:

求 12^(1/12) :

@Test
public void bigMathPowTest() {
    MathContext mathContext = new MathContext(17); //指定计算结果的精度
    BigDecimal a =new BigDecimal("12");
    BigDecimal z= new BigDecimal("1");
    BigDecimal m= new BigDecimal("12");
    BigDecimal p= z.divide(m,18, RoundingMode.HALF_UP);
    System.out.println(BigDecimalMath.pow(a,p,mathContext));
}

将在控制台上产生以下输出:

1.2300755055779713

正在更新中..................................

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/723936.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号