summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md7
-rw-r--r--liblali.c9
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")