Skip to content

Commit

Permalink
Adding erfcinv match function
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikmota committed May 26, 2024
1 parent 31a0777 commit 210cd8f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions evaldo/builtins_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,26 @@ var Builtins_math = map[string]*env.Builtin{
}
},
},
"erfcinv": {
Argsn: 1,
Doc: "Returns the inverse of erfc(x) function.",
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch val := arg0.(type) {
case env.Integer:
if val.Value < 0 || val.Value > 2 {
return MakeBuiltinError(ps, "Invalid input: erfcinv is only defined for 0 <= x <= 2.", "erfcinv")
}
return *env.NewDecimal(math.Erfcinv(float64(val.Value)))
case env.Decimal:
if val.Value < 0 || val.Value > 2 {
return MakeBuiltinError(ps, "Invalid input: erfcinv is only defined for 0 <= x <= 2.", "erfcinv")
}
return *env.NewDecimal(math.Erfcinv(val.Value))
default:
return MakeArgError(ps, 1, []env.Type{env.IntegerType, env.DecimalType}, "erfcinv")
}
},
},
"pi": {
Argsn: 0,
Doc: "Return Pi constant.",
Expand Down

0 comments on commit 210cd8f

Please sign in to comment.