Skip to content

Commit

Permalink
chore: fix formula
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Nov 8, 2024
1 parent 2301ef7 commit fd98d30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@ export class UnderlyingFormulaVisitor extends FormulaParserVisitor<string> {
})
.with("SQRT", () => {
const args = this.arguments(ctx)
return `SQRT(${args[0]})`
// 使用幂运算来实现平方根: x^0.5 = √x
return `POWER(${args[0]}, 0.5)`
})
.with("POWER", () => {
const args = this.arguments(ctx)
// 使用 exp 和 ln 实现幂运算: a^b = e^(b*ln(a))
return `POWER(${args[0]}, ${args[1]})`
})
.with("MOD", () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/template/src/templates/test.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@
"fn": "{{count1}} - {{count2}}"
}
},
"Mod": {
"id": "mod",
"type": "formula",
"option": {
"fn": "MOD({{count3}}, {{count2}})"
}
},
"Abs": {
"id": "abs",
"type": "formula",
Expand Down

0 comments on commit fd98d30

Please sign in to comment.