impliment do wraps

This commit is contained in:
2023-03-11 01:43:37 +00:00
parent 6dcb996f61
commit 597be4e0df
15 changed files with 193 additions and 64 deletions

View File

@@ -1,7 +1,5 @@
package main
import "github.com/wadey/go-rounding"
var vars = scope{}
func init() {
@@ -67,35 +65,10 @@ func init() {
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot create array from '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["round"] = builtinFunc{"round", func(a ...any) (any, ArErr) {
if len(a) == 0 {
return nil, ArErr{TYPE: "round", message: "round takes 1 argument",
EXISTS: true}
}
precision := newNumber()
if len(a) > 1 {
switch x := a[1].(type) {
case number:
if !x.IsInt() {
return nil, ArErr{TYPE: "TypeError", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
}
precision = x
default:
return nil, ArErr{TYPE: "TypeError", message: "Cannot round to '" + typeof(a[1]) + "'", EXISTS: true}
}
}
switch x := a[0].(type) {
case number:
return rounding.Round(newNumber().Set(x), int(precision.Num().Int64()), rounding.HalfUp), ArErr{}
}
return nil, ArErr{TYPE: "TypeError", message: "Cannot round '" + typeof(a[0]) + "'", EXISTS: true}
}}
vars["maths"] = maths
vars["time"] = ArTime
vars["PI"] = PI
vars["π"] = PI
vars["e"] = e
sqrt := builtinFunc{"sqrt", ArgonSqrt}
vars["sqrt"] = sqrt
vars["thread"] = builtinFunc{"thread", ArThread}
}