mirror of
https://github.com/Open-Argon/argon-v3.git
synced 2025-12-06 08:56:07 +00:00
impliment do wraps
This commit is contained in:
@@ -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}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user