Commit 0816bb3159e528d39decce572f458bcdd18af841

Thomas de Grivel 2024-03-07T08:33:05

only accept positive denominator for ratios

diff --git a/.ic3_history b/.ic3_history
index 054a827..f704596 100644
--- a/.ic3_history
+++ b/.ic3_history
@@ -1,8 +1,3 @@
-if_then_else
-féls
-false
-if true && true
-  1 + 1
   2 + 2
 else
   3 + 3
@@ -97,3 +92,8 @@ sq(1 +i 0.5)
 sq(1 +i 1/2)
 (Ratio) 1
 quote (Complex) 0
+-1/-1
+-1/-1 + 1
+-1/-1 + 1/1
+-1/-1
+-1/1
diff --git a/libc3/buf_parse.c b/libc3/buf_parse.c
index 05ab11d..8e4be43 100644
--- a/libc3/buf_parse.c
+++ b/libc3/buf_parse.c
@@ -2725,6 +2725,10 @@ sw buf_parse_ratio (s_buf *buf, s_ratio *dest)
   if ((r = buf_parse_integer(buf, &tmp.denominator)) <= 0)
     goto restore;
   result += r;
+  if (! integer_is_positive(&tmp.denominator)) {
+    r = -1;
+    goto restore;
+  }
   *dest = tmp;
   r = result;
   goto clean;