diff options
| author | Daniel Cerqueira <dan.git@lispclub.com> | 2026-08-21 23:04:56 +0100 |
|---|---|---|
| committer | Daniel Cerqueira <dan.git@lispclub.com> | 2026-08-21 23:44:41 +0100 |
| commit | 10795731901a9c0fc5fb82f037e18def9bb2011d (patch) | |
| tree | 49298ad356a38eff28656fc8b81183839025958a | |
| parent | 8ff3147e497c12bc2c80d0a2b4311afff3920d05 (diff) | |
(- +0) returns -0
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | liblali.c | 9 |
2 files changed, 14 insertions, 2 deletions
@@ -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 @@ -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") |
