1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-26 20:28:49 +08:00

Add Math.round

This commit is contained in:
Robert Krimen
2013-02-27 15:50:52 -08:00
parent 5baaa111e1
commit 252e132594
3 changed files with 26 additions and 0 deletions

View File

@@ -115,6 +115,15 @@ func builtinMath_random(call FunctionCall) Value {
return toValue(rand.Float64())
}
func builtinMath_round(call FunctionCall) Value {
number := toFloat(call.Argument(0))
value := math.Floor(number + 0.5)
if value == 0 {
value = math.Copysign(0, number)
}
return toValue(value)
}
func builtinMath_sin(call FunctionCall) Value {
number := toFloat(call.Argument(0))
return toValue(math.Sin(number))