gunshi-project-ss/src/main/java/com/gunshi/project/xyt/util/BigdecimalUtil.java

52 lines
1.6 KiB
Java
Raw Normal View History

2024-11-07 14:54:41 +08:00
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));
}
}