[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*To*: <srfi-77@xxxxxxxxxxxxxxxxx>*Subject*: Re: Integer residue-classes*From*: Paul Schlie <schlie@xxxxxxxxxxx>*Date*: Sun, 05 Mar 2006 13:51:55 -0500*Delivered-to*: srfi-77@xxxxxxxxxxxxxxxxx*In-reply-to*: <y9l7j7ii2vy.fsf@xxxxxxxxxxxxxxxxxxxxxxxxxxx>*Thread-index*: AcZAhd9uHgIAUKx5EdqeDwADk1ictA==*Thread-topic*: Integer residue-classes*User-agent*: Microsoft-Entourage/11.2.1.051004

Or possibly alternatively, being somewhat simpler: ; n/d :: (+ (div n d) (rem/d n d)) ; symmetric about 0 ; n/d :: (+ (quo n d) (abs (mod/d n d))) ; asymmetric about 0 (define (/: n d) ; for NaN vs. div/0 error. (if (= d 0) +nan.0 (/ n d))) ;--- (define (div n d) ; symmetric about 0 (truncate (/: n d))) (define (rem n d) ; same sign as (div n d) ((if (< d 0) - +) (- n (* (div n d) d)))) (define (rem/d n d) ; remainder fraction (/: (rem n d) (abs d))) ; n/d :: (+ (div n d) (rem/d n d)) ;--- (define (quo n d) ; asymmetric about 0 (floor (/: n d))) (define (mod n d) ; same sign as d (- n (* (quo n d) d))) (define (mod/d n d) ; modular fraction (/: (mod n d) (abs d))) ; n/d :: (+ (quo n d) (abs (mod/d n d))) Thereby: (div x 0) :: (quo x 0) => NaN (rem x 0) :: (mod x 0) => x (rem/d x 0) :: (mod/d x 0) => NaN

**Follow-Ups**:**Re: Integer residue-classes***From:*Paul Schlie

**References**:**Re: Integer residue-classes***From:*Michael Sperber

- Prev by Date:
**Re: Multiple precisions of floating-point arithmetic** - Next by Date:
**implementations that can't represent infinities or NaNs** - Previous by thread:
**Re: Integer residue-classes** - Next by thread:
**Re: Integer residue-classes** - Index(es):