feat(codemode): math parity (#35609)
This commit is contained in:
parent
df471872de
commit
ba24037e64
6 changed files with 172 additions and 18 deletions
|
|
@ -4,6 +4,13 @@ export const mathMethods = new Set([
|
|||
"max",
|
||||
"min",
|
||||
"abs",
|
||||
"acos",
|
||||
"acosh",
|
||||
"asin",
|
||||
"asinh",
|
||||
"atan",
|
||||
"atan2",
|
||||
"atanh",
|
||||
"floor",
|
||||
"ceil",
|
||||
"round",
|
||||
|
|
@ -13,10 +20,22 @@ export const mathMethods = new Set([
|
|||
"cbrt",
|
||||
"pow",
|
||||
"hypot",
|
||||
"cos",
|
||||
"cosh",
|
||||
"sin",
|
||||
"sinh",
|
||||
"tan",
|
||||
"tanh",
|
||||
"log",
|
||||
"log2",
|
||||
"log10",
|
||||
"log1p",
|
||||
"exp",
|
||||
"expm1",
|
||||
"f16round",
|
||||
"fround",
|
||||
"clz32",
|
||||
"imul",
|
||||
])
|
||||
|
||||
export const invokeMathMethod = (name: string, args: Array<unknown>, node: AstNode): number => {
|
||||
|
|
@ -33,6 +52,20 @@ export const invokeMathMethod = (name: string, args: Array<unknown>, node: AstNo
|
|||
return Math.min(...nums)
|
||||
case "abs":
|
||||
return Math.abs(a)
|
||||
case "acos":
|
||||
return Math.acos(a)
|
||||
case "acosh":
|
||||
return Math.acosh(a)
|
||||
case "asin":
|
||||
return Math.asin(a)
|
||||
case "asinh":
|
||||
return Math.asinh(a)
|
||||
case "atan":
|
||||
return Math.atan(a)
|
||||
case "atan2":
|
||||
return Math.atan2(a, b)
|
||||
case "atanh":
|
||||
return Math.atanh(a)
|
||||
case "floor":
|
||||
return Math.floor(a)
|
||||
case "ceil":
|
||||
|
|
@ -51,14 +84,38 @@ export const invokeMathMethod = (name: string, args: Array<unknown>, node: AstNo
|
|||
return Math.pow(a, b)
|
||||
case "hypot":
|
||||
return Math.hypot(...nums)
|
||||
case "cos":
|
||||
return Math.cos(a)
|
||||
case "cosh":
|
||||
return Math.cosh(a)
|
||||
case "sin":
|
||||
return Math.sin(a)
|
||||
case "sinh":
|
||||
return Math.sinh(a)
|
||||
case "tan":
|
||||
return Math.tan(a)
|
||||
case "tanh":
|
||||
return Math.tanh(a)
|
||||
case "log":
|
||||
return Math.log(a)
|
||||
case "log2":
|
||||
return Math.log2(a)
|
||||
case "log10":
|
||||
return Math.log10(a)
|
||||
case "log1p":
|
||||
return Math.log1p(a)
|
||||
case "exp":
|
||||
return Math.exp(a)
|
||||
case "expm1":
|
||||
return Math.expm1(a)
|
||||
case "f16round":
|
||||
return Math.f16round(a)
|
||||
case "fround":
|
||||
return Math.fround(a)
|
||||
case "clz32":
|
||||
return Math.clz32(a)
|
||||
case "imul":
|
||||
return Math.imul(a, b)
|
||||
}
|
||||
throw new InterpreterRuntimeError(`Math.${name} is not available in CodeMode.`, node)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue