模块 jmc.utils
程序包 com.jmc.math.exp

类 ExactExp

java.lang.Object
com.jmc.math.exp.ExactExp

public class ExactExp extends Object
精准计算表达式的结果
从以下版本开始:
1.0
  • 方法详细资料

    • getResult

      public static BigDecimal getResult(String infixExp)
      将表达式的计算结果转换为精度16的BigDecimal
      参数:
      infixExp - 表达式
      返回:
      精度为16的BigDecimal
      API Note:
      
       // 计算表达式"1 + √(5 + 20) + √4 + 2"(结果:10)
       BigDecimal res = ExactExp.getResult("1 + (√(5 + 20)) + (√4) + 2");
      
       // n! ~ √(2πn) * (n/e)^n
       var exp = "√(2 * %.16f * %d) * (%d / %.16f) ^ %d"
               .formatted(Math.PI, n, n, Math.E, n);
       // 计算n!近似表达式的结果
       res = ExactExp.getResult(exp);
       
    • getResult

      public static BigDecimal getResult(String infixExp, int scale)
      将表达式的计算结果转换为指定精度的BigDecimal
      参数:
      infixExp - 中缀表达式
      scale - 精度(保留小数位数)
      返回:
      指定精度的BigDecimal
      API Note:
      
       // 计算表达式"√3",保留5位小数(结果:1.73205)
       BigDecimal res = ExactExp.getResult("√3", 5);