diff --git a/math.c b/math.c index 8a9c023b..e1fbf006 100644 --- a/math.c +++ b/math.c @@ -143,3 +143,13 @@ logior (SCM x) ///((arity . n)) } return make_number (n); } + +SCM +ash (SCM n, SCM count) +{ + assert (TYPE (n) == NUMBER); + assert (TYPE (count) == NUMBER); + int cn = VALUE (n); + int ccount = VALUE (count); + return make_number ((ccount < 0) ? cn >> -ccount : cn << ccount); +} diff --git a/tests/scm.test b/tests/scm.test index 955b3c5a..c936b367 100755 --- a/tests/scm.test +++ b/tests/scm.test @@ -60,6 +60,10 @@ exit $? (pass-if "modulo" (seq? (modulo 11 3) 2)) (pass-if "expt" (seq? (expt 2 3) 8)) (pass-if "logior" (seq? (logior 0 1 2 4) 7)) +(pass-if-equal "ash" + 8 (ash 1 3)) +(pass-if-equal "ash -1" + 5 (ash 10 -1)) (pass-if "=" (seq? 3 '3)) (pass-if "= 2" (not (= 3 '4)))