mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-08 05:27:35 +02:00
Shortcut for general quotient/remainder with a denominator of 1.
This commit is contained in:
parent
297e8727cb
commit
7d38ec4786
2 changed files with 8 additions and 1 deletions
2
bignum.c
2
bignum.c
|
@ -1474,6 +1474,7 @@ sexp sexp_quotient (sexp ctx, sexp a, sexp b) {
|
||||||
int at=sexp_number_type(a), bt=sexp_number_type(b);
|
int at=sexp_number_type(a), bt=sexp_number_type(b);
|
||||||
sexp r=SEXP_VOID;
|
sexp r=SEXP_VOID;
|
||||||
sexp_gc_var1(tmp);
|
sexp_gc_var1(tmp);
|
||||||
|
if (b == SEXP_ONE) return a;
|
||||||
sexp_gc_preserve1(ctx, tmp);
|
sexp_gc_preserve1(ctx, tmp);
|
||||||
switch ((at * SEXP_NUM_NUMBER_TYPES) + bt) {
|
switch ((at * SEXP_NUM_NUMBER_TYPES) + bt) {
|
||||||
case SEXP_NUM_NOT_NOT: case SEXP_NUM_NOT_FIX:
|
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);
|
int at=sexp_number_type(a), bt=sexp_number_type(b);
|
||||||
sexp r=SEXP_VOID;
|
sexp r=SEXP_VOID;
|
||||||
sexp_gc_var1(tmp);
|
sexp_gc_var1(tmp);
|
||||||
|
if (b == SEXP_ONE) return SEXP_ZERO;
|
||||||
sexp_gc_preserve1(ctx, tmp);
|
sexp_gc_preserve1(ctx, tmp);
|
||||||
switch ((at * SEXP_NUM_NUMBER_TYPES) + bt) {
|
switch ((at * SEXP_NUM_NUMBER_TYPES) + bt) {
|
||||||
case SEXP_NUM_NOT_NOT: case SEXP_NUM_NOT_FIX:
|
case SEXP_NUM_NOT_NOT: case SEXP_NUM_NOT_FIX:
|
||||||
|
|
|
@ -173,7 +173,12 @@
|
||||||
(test #t (< 1.0 3/2))
|
(test #t (< 1.0 3/2))
|
||||||
(test #t (< 1/2 1.5))
|
(test #t (< 1/2 1.5))
|
||||||
(test #t (< 1/2 2.0))
|
(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
|
(else
|
||||||
#f))
|
#f))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue