From c93f0effa6c5b886b57669b8d7f984f0c0019463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Wed, 3 Dec 1997 14:47:41 -0800 Subject: [PATCH] division now always rounds towards minus infinity (I hope) Rev: src/operators.c:1.21 Rev: src/testsuite.in:1.62 Rev: tutorial/tutorial.wmml:1.36 --- src/operators.c | 10 ++++++---- src/testsuite.in | 3 ++- tutorial/tutorial.wmml | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/operators.c b/src/operators.c index 75f4dc8a4b..dbc6eb4b0a 100644 --- a/src/operators.c +++ b/src/operators.c @@ -5,7 +5,7 @@ \*/ #include <math.h> #include "global.h" -RCSID("$Id: operators.c,v 1.20 1997/10/11 06:48:24 hubbe Exp $"); +RCSID("$Id: operators.c,v 1.21 1997/12/03 22:46:17 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "multiset.h" @@ -1071,10 +1071,12 @@ void o_divide(void) error("Division by zero\n"); sp--; - tmp=sp[-1].u.integer / sp[0].u.integer; - if(tmp<0) - if(tmp * sp[0].u.integer > sp[-1].u.integer) + tmp=sp[-1].u.integer/sp[0].u.integer; + + if((sp[-1].u.integer<0) != (sp[0].u.integer<0)) + if(tmp*sp[0].u.integer!=sp[-1].u.integer) tmp--; + sp[-1].u.integer=tmp; return; } diff --git a/src/testsuite.in b/src/testsuite.in index e80ab265a4..5fae3d71ab 100644 --- a/src/testsuite.in +++ b/src/testsuite.in @@ -1,4 +1,4 @@ -test_true([["$Id: testsuite.in,v 1.61 1997/11/13 22:13:29 hubbe Exp $"]]) +test_true([["$Id: testsuite.in,v 1.62 1997/12/03 22:46:18 hubbe Exp $"]]) test_eq(1e1,10.0) test_eq(1E1,10.0) test_eq(1e+1,10.0) @@ -631,6 +631,7 @@ test_eq(12/3,4) test_eq(13/3,4) test_eq(14/3,4) test_eq(15/3,5) +test_eq(-2/4,-1) test_eq(-12/3,-4) test_eq(-13/3,-5) test_eq(-14/3,-5) diff --git a/tutorial/tutorial.wmml b/tutorial/tutorial.wmml index a921ac718f..bc40baad66 100644 --- a/tutorial/tutorial.wmml +++ b/tutorial/tutorial.wmml @@ -2218,7 +2218,7 @@ the complete list of combinations of types you can use with these operators: </tr> <tr> -<td><tt><i>int</i> / <i>int</i></tt></td><td>int</td><td>The right integer divided by the left integer rounded towards zero.</td> +<td><tt><i>int</i> / <i>int</i></tt></td><td>int</td><td>The right integer divided by the left integer rounded towards minus infinity.</td> </tr> <tr> -- GitLab