1
0
forked from Mirror/wren

Add Num .round

This commit is contained in:
Kyle Charters
2017-09-20 20:27:02 -04:00
parent d390e16a99
commit 84f2252c68
4 changed files with 20 additions and 0 deletions

View File

@ -19,3 +19,4 @@ Will Speak <will@willspeak.me>
Damien Radtke <damienradtke@gmail.com>
Max Ferguson <maxxferguson@gmail.com>
Sven Bergström <sven@underscorediscovery.com>
Kyle Charters <kylewcharters@gmail.com>

View File

@ -97,6 +97,15 @@ The natural logarithm of the number.
Raises this number (the base) to `power`. Returns `nan` if the base is negative.
### **round**
Rounds the number to the nearest integer.
:::wren
System.print(1.5.round) //> 2
System.print((-3.2).round) //> -3
System.print((-3.7).round) //> -4
### **sin**
The sine of the number.

View File

@ -593,6 +593,7 @@ DEF_NUM_FN(ceil, ceil)
DEF_NUM_FN(cos, cos)
DEF_NUM_FN(floor, floor)
DEF_NUM_FN(negate, -)
DEF_NUM_FN(round, round)
DEF_NUM_FN(sin, sin)
DEF_NUM_FN(sqrt, sqrt)
DEF_NUM_FN(tan, tan)
@ -1270,6 +1271,7 @@ void wrenInitializeCore(WrenVM* vm)
PRIMITIVE(vm->numClass, "cos", num_cos);
PRIMITIVE(vm->numClass, "floor", num_floor);
PRIMITIVE(vm->numClass, "-", num_negate);
PRIMITIVE(vm->numClass, "round", num_round);
PRIMITIVE(vm->numClass, "sin", num_sin);
PRIMITIVE(vm->numClass, "sqrt", num_sqrt);
PRIMITIVE(vm->numClass, "tan", num_tan);

View File

@ -0,0 +1,8 @@
System.print(123.round) // expect: 123
System.print((-123).round) // expect: -123
System.print(0.round) // expect: 0
System.print((-0).round) // expect: -0
System.print(0.123.round) // expect: 0
System.print(12.3.round) // expect: 12
System.print((-0.123).round) // expect: -0
System.print((-12.3).round) // expect: -12