feat: add Num.round method for rounding numbers to nearest integer

Implement the `round` method on the Num class in the Wren VM, which rounds a number to the nearest integer using standard rounding rules (away from zero for .5). The implementation adds a new `DEF_NUM_FN(round, round)` macro invocation in `wren_core.c`, registers the corresponding primitive `num_round`, and includes comprehensive documentation in the core module reference. A new test file `test/core/number/round.wren` validates behavior for positive, negative, zero, and fractional values. Also adds Kyle Charters to the AUTHORS file.
This commit is contained in:
Bob Nystrom
2017-10-06 14:51:55 +00:00
4 changed files with 20 additions and 0 deletions
+9
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.