From fc866f896fc88dd082a0c8a6a0196ab903bce855 Mon Sep 17 00:00:00 2001 From: Marco Lizza Date: Wed, 4 Mar 2015 14:45:51 +0100 Subject: [PATCH] Extending 'sign' method to handle also "equal to zero" case. --- src/wren_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wren_core.c b/src/wren_core.c index 91b07aed..cdc5d9c1 100644 --- a/src/wren_core.c +++ b/src/wren_core.c @@ -906,7 +906,17 @@ DEF_PRIMITIVE(num_rad) DEF_PRIMITIVE(num_sign) { - RETURN_NUM(AS_NUM(args[0]) >= 0.0 ? 1 : -1); + double num = AS_NUM(args[0]); + double sign; + if (num > 0) { + sign = 1; + } else + if (num < 0) { + sign = -1; + } else { + sign = 0; + } + RETURN_NUM(sign); } DEF_PRIMITIVE(num_sin)