# FormulaCalculation **Repository Path**: feixiangjusha/formula-calculation ## Basic Information - **Project Name**: FormulaCalculation - **Description**: 字符串公式计算,支持自定义函数 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2022-06-21 - **Last Updated**: 2024-02-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 字符串公式解析器 * 支持普通+-\*/^公式,如`1+2^2*6/3-2=7` * 支持常量 π(pi) E(e) * 支持函数 random, arccos, sin, ceil, fact, cot, cos, pow, log, ln, lg, abs, arctan, floor, csc, tan, e, sec, pi, round, arcsin, sqrt * 支持函数扩展 # 函数扩展 扩展常量或无参函数 `ManageFunctions.add(String name, IProcessFunction function)` 扩展带参函数 `ManageFunctions.add(String name, int paramCount, IProcessFunction function) ` 例子 添加四舍五入函数 ``` java ManageFunctions.add("round", 1, args -> new Result(Math.round(args[0]))); ``` # 原理 标准中缀表达式转后缀表达式,当自定义函数时对调了函数和左括号顺序 # 其他 没做太多极限测试,表达式解析特别是自定义函数部分可能会存在bug