52 lines
1.6 KiB
Java
52 lines
1.6 KiB
Java
|
|
package com.gunshi.project.xyt.util;
|
||
|
|
|
||
|
|
import java.math.BigDecimal;
|
||
|
|
import java.math.MathContext;
|
||
|
|
import java.math.RoundingMode;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author cxw
|
||
|
|
* @description
|
||
|
|
* @classname BigdecimalUtil.java
|
||
|
|
* @create 2024-11-06, 星期三, 10:33:41
|
||
|
|
*/
|
||
|
|
public class BigdecimalUtil {
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @description: 小数指数计算
|
||
|
|
* @param base 底数
|
||
|
|
* @param exponent 指数
|
||
|
|
* @return: java.math.BigDecimal
|
||
|
|
* @auther: cxw
|
||
|
|
* @date: 2024-11-06, 周三, 10:34:47
|
||
|
|
*/
|
||
|
|
public static BigDecimal bigDecimalExponentiation(BigDecimal base, double exponent) {
|
||
|
|
BigDecimal result = BigDecimal.valueOf(Math.pow(base.doubleValue(), exponent)).round(new MathContext(10, RoundingMode.HALF_UP));
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @description: 计算x的伽马函数
|
||
|
|
* @param x
|
||
|
|
* @return: java.math.BigDecimal
|
||
|
|
* @auther: cxw
|
||
|
|
* @date: 2024-11-06, 周三, 11:31:24
|
||
|
|
*/
|
||
|
|
public static BigDecimal bigDecimalGamma(BigDecimal x) {
|
||
|
|
BigDecimal result = BigDecimal.valueOf(gamma(x.doubleValue()));
|
||
|
|
return result.setScale(x.scale(), RoundingMode.HALF_UP);
|
||
|
|
}
|
||
|
|
public static double gamma(double x) {
|
||
|
|
return Math.exp(logGamma(x));
|
||
|
|
}
|
||
|
|
public static double logGamma(double x) {
|
||
|
|
double tmp = (x - 0.5) * Math.log(x + 4.5) - (x + 4.5);
|
||
|
|
double ser = 1.0 + 76.18009173 / (x + 0) - 86.50532033 / (x + 1)
|
||
|
|
+ 24.01409822 / (x + 2) - 1.231739516 / (x + 3)
|
||
|
|
+ 0.00120858003 / (x + 4) - 0.00000536382 / (x + 5);
|
||
|
|
return tmp + Math.log(ser * Math.sqrt(2 * Math.PI));
|
||
|
|
}
|
||
|
|
}
|