Categorygithub.com/xymodule/formula
repositorypackage
0.0.0-20191118083052-d9afe6e3273b
Repository: https://github.com/xymodule/formula.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

formula

支持对数学运算的编译执行,主要支持以下数学公式:

  • 支持四则运算
  • 支持三角函数
  • 支持位运算
  • 支持三元操作
  • 支持逻辑运算符
  • 支持自定义参数
  • 支持自定义函数
  • 支持公式缓存

支持lua

  • 支持lua缓存

内置函数如下表

函数名称参数个数调用方式结果
abs1abs(-1)1
acos1acos(sqrt(3)/2)0.5235987755982991 (π/6)
asin1asin(1/2)0.5235987755982991 (π/6)
asin1asin(1)π/2
atan1atan(1)0.7853981633974483 (π/4)
ceil1ceil(3.4)4
concatnconcat(1,23,hello)123hello
cos1cos(π/3)0.5000000000000001
/23/40.75
exp1exp(3.3)27.112638920657883
floor1floor(2.2)2
>23 > 2true
if3iif(3 > 2,π,10)3.141592653589793
<23 < 2false
innin(3,3,4,5)true
ln1ln(2.718281828)0.9999999998311266
log21log2(16)4
log101log10(100000)5
log2log(100,10)2
maxnmax(-1,2,3.1) = 3.13.1
minnmin(-1,2,3.1) = -1-1
mod2mod(5,2)1
*23*3.410.2
+25+1015
pow2pow(10,2)100
round2round(100.11)100
sign1sign(100)false
sin1sin(π/6)0.49999999999999994
-23-6-3
tan1tan(π/4)1
truncate1truncate(12.3)12
>>22>>11
<<21<<12

调用方法

  • 普通数学公式调用
params := make(map[string]interface{})
r,err:=HandleFormula("1+2",params)
if err!=nil{
    //handle err
}