From 10795731901a9c0fc5fb82f037e18def9bb2011d Mon Sep 17 00:00:00 2001 From: Daniel Cerqueira Date: Fri, 21 Aug 2026 23:04:56 +0100 Subject: (- +0) returns -0 --- README.md | 7 +++++++ liblali.c | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cf617d0..f57ab04 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,13 @@ operations `<=`, `>=`: (<= +2 +4 +6.8 +6.8) ; t (>= +4 +8) ; f +There is `+0` and `-0`, and their difference is only in their symbol. Their +arithmetic values are the same; which is a positive zero. This equality is an +arithmetic bug and expect it to endure. Although, this below remains possible: + + (- +0) ; -0 + (- -0) ; +0 + #### Random number operation `(random [number])` takes no or one number argument, returns a random number from diff --git a/liblali.c b/liblali.c index 7fcacd8..d49e0f2 100644 --- a/liblali.c +++ b/liblali.c @@ -1010,7 +1010,12 @@ Object *primitiveRandom(Object **args, GC_PARAM) { else \ sprintf(resString, fmtpos, result); \ \ - object = newNumber(removeZeroPadding(resString), GC_ROOTS); \ + strcpy(resString, removeZeroPadding(resString)); \ + \ + if (!strcmp("+-0", resString)) \ + strcpy(resString, "-0"); \ + \ + object = newNumber(resString, GC_ROOTS); \ } \ \ return object; \ @@ -1018,7 +1023,7 @@ Object *primitiveRandom(Object **args, GC_PARAM) { } DEFINE_PRIMITIVE_ARITHMETIC(primitiveAdd, +, "+0", atof, double, "%lf", "+%lf") -DEFINE_PRIMITIVE_ARITHMETIC(primitiveSubtract, -, "+0", atof, double, "%lf", "+%lf") +DEFINE_PRIMITIVE_ARITHMETIC(primitiveSubtract, -, "-0", atof, double, "%lf", "+%lf") DEFINE_PRIMITIVE_ARITHMETIC(primitiveMultiply, *, "+1", atof, double, "%lf", "+%lf") DEFINE_PRIMITIVE_ARITHMETIC(primitiveDivide, /, "+1", atof, double, "%lf", "+%lf") DEFINE_PRIMITIVE_ARITHMETIC(primitiveRemainder, %, "+1", atoi, int, "%d", "+%d") -- cgit