[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, 12 Mar 2006 10:29:36 -0500*Delivered-to*: srfi-77@xxxxxxxxxxxxxxxxx*In-reply-to*: <C0309D7B.D145%schlie@xxxxxxxxxxx>*Thread-index*: AcZAhd9uHgIAUKx5EdqeDwADk1ictAFY+V49*Thread-topic*: Integer residue-classes*User-agent*: Microsoft-Entourage/11.2.1.051004

sorry for the noise, but seeming further simpler and consistent: ; n/d :: (+ (div n d) (r/d n d)) ; symmetric about 0 ; n/d :: (+ (quo n d) (m/d n d)) ; asymmetric about 0 ; where if (* 0 NaN) => 0 and (/ 0) => NaN ; then (/ 0 0) must => 0, to be consistent. (define (/: n d) ; for NaN vs. div/0 error. (cond ((= n 0) 0) ((= d 0) +nan.0) (else (/ n d)))) ; thereby: ; (div 0 x) => 0 (quo 0 x) => 0 ; (rem 0 x) => 0 (mod 0 x) => 0 ; (r/d 0 x) => 0 (m/d 0 x) => 0 ; otherwise: ; (div x 0) => NaN (quo x 0) => NaN ; (rem x 0) => 0 (mod x 0) => x ; (r/d x 0) => 0 (m/d x 0) => NaN ;--- (define (div n d) ; symmetric about 0 (truncate (/: n d))) (define (rem n d) ; same sign as (div n d) (* (/: d (abs d)) (- n (* (div n d) d)))) (define (r/d n d) ; remainder fraction (/: (rem n d) (abs d))) ; n/d :: (+ (div n d) (r/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 (m/d n d) ; modular fraction (/: (mod n d) d)) ; n/d :: (+ (quo n d) (m/d n d)) ;---

**Follow-Ups**:**miscellaneous request***From:*Paul Schlie

**References**:**Re: Integer residue-classes***From:*Paul Schlie

- Prev by Date:
**implementations that can't represent infinities or NaNs** - Next by Date:
**miscellaneous request** - Previous by thread:
**Re: Integer residue-classes** - Next by thread:
**miscellaneous request** - Index(es):