Shortcut for general quotient/remainder with a denominator of 1.

This commit is contained in:
Alex Shinn 2014-01-20 22:51:36 +09:00
parent 297e8727cb
commit 7d38ec4786
2 changed files with 8 additions and 1 deletions

View file

@ -1474,6 +1474,7 @@ sexp sexp_quotient (sexp ctx, sexp a, sexp b) {
int at=sexp_number_type(a), bt=sexp_number_type(b);
sexp r=SEXP_VOID;
sexp_gc_var1(tmp);
if (b == SEXP_ONE) return a;
sexp_gc_preserve1(ctx, tmp);
switch ((at * SEXP_NUM_NUMBER_TYPES) + bt) {
case SEXP_NUM_NOT_NOT: case SEXP_NUM_NOT_FIX:
@ -1548,6 +1549,7 @@ sexp sexp_remainder (sexp ctx, sexp a, sexp b) {
int at=sexp_number_type(a), bt=sexp_number_type(b);
sexp r=SEXP_VOID;
sexp_gc_var1(tmp);
if (b == SEXP_ONE) return SEXP_ZERO;
sexp_gc_preserve1(ctx, tmp);
switch ((at * SEXP_NUM_NUMBER_TYPES) + bt) {
case SEXP_NUM_NOT_NOT: case SEXP_NUM_NOT_FIX:

View file

@ -173,7 +173,12 @@
(test #t (< 1.0 3/2))
(test #t (< 1/2 1.5))
(test #t (< 1/2 2.0))
(test 1.0 (max 1/2 1.0)))
(test 1.0 (max 1/2 1.0))
(test 18446744073709551617 (numerator (/ 18446744073709551617 2)))
(test "18446744073709551617/2" (number->string (/ 18446744073709551617 2)))
(let ((r (/ (expt 2 61) 3)))
(test 0 (- r r))
(test 2305843009213693952/3 r)))
(else
#f))