mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Add Num .round
This commit is contained in:
1
AUTHORS
1
AUTHORS
@ -19,3 +19,4 @@ Will Speak <will@willspeak.me>
|
|||||||
Damien Radtke <damienradtke@gmail.com>
|
Damien Radtke <damienradtke@gmail.com>
|
||||||
Max Ferguson <maxxferguson@gmail.com>
|
Max Ferguson <maxxferguson@gmail.com>
|
||||||
Sven Bergström <sven@underscorediscovery.com>
|
Sven Bergström <sven@underscorediscovery.com>
|
||||||
|
Kyle Charters <kylewcharters@gmail.com>
|
||||||
|
|||||||
@ -97,6 +97,15 @@ The natural logarithm of the number.
|
|||||||
|
|
||||||
Raises this number (the base) to `power`. Returns `nan` if the base is negative.
|
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**
|
### **sin**
|
||||||
|
|
||||||
The sine of the number.
|
The sine of the number.
|
||||||
|
|||||||
@ -593,6 +593,7 @@ DEF_NUM_FN(ceil, ceil)
|
|||||||
DEF_NUM_FN(cos, cos)
|
DEF_NUM_FN(cos, cos)
|
||||||
DEF_NUM_FN(floor, floor)
|
DEF_NUM_FN(floor, floor)
|
||||||
DEF_NUM_FN(negate, -)
|
DEF_NUM_FN(negate, -)
|
||||||
|
DEF_NUM_FN(round, round)
|
||||||
DEF_NUM_FN(sin, sin)
|
DEF_NUM_FN(sin, sin)
|
||||||
DEF_NUM_FN(sqrt, sqrt)
|
DEF_NUM_FN(sqrt, sqrt)
|
||||||
DEF_NUM_FN(tan, tan)
|
DEF_NUM_FN(tan, tan)
|
||||||
@ -1270,6 +1271,7 @@ void wrenInitializeCore(WrenVM* vm)
|
|||||||
PRIMITIVE(vm->numClass, "cos", num_cos);
|
PRIMITIVE(vm->numClass, "cos", num_cos);
|
||||||
PRIMITIVE(vm->numClass, "floor", num_floor);
|
PRIMITIVE(vm->numClass, "floor", num_floor);
|
||||||
PRIMITIVE(vm->numClass, "-", num_negate);
|
PRIMITIVE(vm->numClass, "-", num_negate);
|
||||||
|
PRIMITIVE(vm->numClass, "round", num_round);
|
||||||
PRIMITIVE(vm->numClass, "sin", num_sin);
|
PRIMITIVE(vm->numClass, "sin", num_sin);
|
||||||
PRIMITIVE(vm->numClass, "sqrt", num_sqrt);
|
PRIMITIVE(vm->numClass, "sqrt", num_sqrt);
|
||||||
PRIMITIVE(vm->numClass, "tan", num_tan);
|
PRIMITIVE(vm->numClass, "tan", num_tan);
|
||||||
|
|||||||
8
test/core/number/round.wren
Normal file
8
test/core/number/round.wren
Normal 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
|
||||||
Reference in New Issue
Block a user