From b08d48bd43b816d84d0355d9335b358837585735 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 22 Jan 2009 12:58:53 +0000 Subject: [PATCH] Added more remainder tests, and fixed our implementation of remainder to pass the tests --- rangetest.c | 4 ++++ support/tock_support.h | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rangetest.c b/rangetest.c index fee4254..0a21367 100644 --- a/rangetest.c +++ b/rangetest.c @@ -125,6 +125,10 @@ int g_stopped; testf(f(-max-1,0,"")); \ testp(0,f(max,max,"")); \ testp(0,f(-max-1,-max-1,"")); \ + testp(-2,f(-max-1,max>>1,"")); \ + testp(-2,f(-max-1,-(max>>1),"")); \ + testp(-1,f(-max,max>>1,"")); \ + testp(-1,f(-max,-(max>>1),"")); \ testp(-1,f(-max-1,-max,"")); \ testp(-1,f(-max-1,max,"")); \ testp(3,f(3,-max-1,"")); \ diff --git a/support/tock_support.h b/support/tock_support.h index 180582f..d9305ba 100644 --- a/support/tock_support.h +++ b/support/tock_support.h @@ -177,8 +177,9 @@ static inline int occam_check_retype (int src, int dest, const char *pos) { static inline type occam_rem_##type (type a, type b, const char *pos) { \ if (b == 0) { \ occam_stop (pos, 1, "modulo by zero"); \ - } \ - if (a < 0) { \ + } else if (a == __MIN(type)) { \ + return a % (b < 0 ? -b : b); \ + } else if (a < 0) { \ return -((-a) % (b < 0 ? -b : b)); \ } else { \ return a % (b < 0 ? -b : b); \