Class MathFunctions

java.lang.Object
cloud.opencode.base.expression.function.MathFunctions

public final class MathFunctions extends Object
Math Functions 数学函数

Provides built-in mathematical functions for expressions.

为表达式提供内置的数学函数。

Features | 主要功能:

  • Basic: abs, neg, ceil, floor, round, trunc, min, max, clamp - 基本运算
  • Power/root: pow, sqrt, cbrt, exp, log, log10, log2 - 幂/根运算
  • Trigonometric: sin, cos, tan, asin, acos, atan, atan2 - 三角函数
  • Conversion: todegrees, toradians, int, long, double, decimal - 转换
  • Aggregate: sum, avg - 聚合
  • Random: random, randomint - 随机数
  • Constants: pi, e - 常量

Usage Examples | 使用示例:

Object result = OpenExpression.eval("round(3.14159, 2)");  // 3.14
Object max = OpenExpression.eval("max(10, 20, 30)");  // 30.0
Object sq = OpenExpression.eval("sqrt(144)");  // 12.0

Security | 安全性:

  • Thread-safe: Yes, stateless utility class with ThreadLocalRandom - 线程安全: 是,使用ThreadLocalRandom的无状态工具类
  • Null-safe: Yes, null arguments treated as 0 - 空值安全: 是,null参数视为0
Since:
JDK 25, opencode-base-expression V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • getFunctions

      public static Map<String,Function> getFunctions()
      Get all math functions 获取所有数学函数
      Returns:
      the function map | 函数映射