* math.c (ash): New function.
* tests/scm.test (ash, ash -1): New tests.
This commit is contained in:
Jan Nieuwenhuizen 2016-12-20 20:10:43 +01:00
parent 7d5c3a0201
commit e97d99c03a
2 changed files with 14 additions and 0 deletions

10
math.c
View file

@ -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);
}

View file

@ -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)))