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
+8
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