Next: , Previous: , Up: syslib numerics   [Index]


12.10.13 Quotient and remainder

These functions perform the integer division between exact and inexact numbers and return two values: the quotient and the remainder. For all the functions: the second argument must be non–zero.

Note that considering:

(quotient+remainder X Y)

according to R6RS:

(define (sign n)
  (cond ((negative? n) -1)
        ((positive? n) 1)
        (else 0)))

(define (quotient n1 n2)
  (* (sign n1) (sign n2) (div (abs n1) (abs n2))))

(define (remainder n1 n2)
  (* (sign n1) (mod (abs n1) (abs n2))))

(define (modulo n1 n2)
  (* (sign n2) (mod (* (sign n2) n1) (abs n2))))

so we have:

sign(quotient)  = sign(X) * sign(Y)
sign(remainder) = sign(X)
sign(modulo)    = sign(Y)

Any number as first argument

Unsafe Operation: $quotient+remainder-number-fixnum num fx

Perform the integer division between any exact or inexact integer and a fixnum. If num is not an integer: an error is raised. Return exact or inexact integers.

Unsafe Operation: $quotient+remainder-number-bignum num bn

Perform the integer division between any exact or inexact integer and a bignum. If num is not an integer: an error is raised. Return exact or inexact integers.

Unsafe Operation: $quotient+remainder-number-flonum num fl

Perform the integer division between any exact or inexact integer and a flonum. If num is not an integer: an error is raised. Return exact or inexact integers.

Any number as second argument

Unsafe Operation: $quotient+remainder-fixnum-number fx num

Perform the integer division between a fixnum and any exact or inexact integer. If num is not an integer: an error is raised. Return exact or inexact integers.

Unsafe Operation: $quotient+remainder-bignum-number bn num

Perform the integer division between a bignum and any exact or inexact integer. If num is not an integer: an error is raised. Return exact or inexact integers.

Unsafe Operation: $quotient+remainder-flonum-number fl num

Perform the integer division between a flonum and any exact or inexact integer. If num is not an integer: an error is raised. Return exact or inexact integers.

Fixnum as first argument

Unsafe Operation: $quotient+remainder-fixnum-fixnum fx1 fx2

Perform the integer division between a fixnum and a fixnum; return a fixnum or bignum as quotient, return a fixnum as remainder.

Unsafe Operation: $quotient+remainder-fixnum-bignum fx bn

Perform the integer division between a fixnum and a bignum; return fixnums.

Unsafe Operation: $quotient+remainder-fixnum-flonum fx fl

Perform the integer division between a fixnum and a flonum; return flonums.

Bignum as first argument

Unsafe Operation: $quotient+remainder-bignum-fixnum bn fx

Perform the integer division between a bignum and a fixnum; return fixnums.

Unsafe Operation: $quotient+remainder-bignum-bignum bn1 bn2

Perform the integer division between a bignum and a bignum; return fixnums or bignums.

Unsafe Operation: $quotient+remainder-bignum-flonum bn fl

Perform the integer division between a bignum and a flonum; return flonums.

Flonum as first argument

Unsafe Operation: $quotient+remainder-flonum-fixnum fl fx

Perform the integer division between a flonum and a fixnum; return flonums.

Unsafe Operation: $quotient+remainder-flonum-bignum fl bn

Perform the integer division between a flonum and a bignum; return flonums.

Unsafe Operation: $quotient+remainder-flonum-flonum fl1 fl2

Perform the integer division between a flonum and a flonum; return flonums.


Next: , Previous: , Up: syslib numerics   [Index]