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:
@@ -594,6 +594,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)
|
||||
@@ -1271,6 +1272,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);
|
||||
|
||||
Reference in New Issue
Block a user