Changeset 35489 in project
 Timestamp:
 04/30/18 00:03:10 (4 months ago)
 Location:
 release/4/srfi27/trunk
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

release/4/srfi27/trunk/srfi27commontypes.scm
r35485 r35489 4 4 ;; Issues 5 5 ;; 6 ;;  cannot restrict number domain w/ type system 7 8 ;; 6 9 7 10 (definetype alist list) 11 12 ;; 13 14 (definetype bignum (struct bignum)) 15 (definetype ratnum (struct ratnum)) 16 (definetype compnum (struct compnum)) 17 18 (definetype fullinteger (or fixnum number bignum)) ;close (;) 19 20 (definetype fullnumber (or fixnum float number bignum ratnum compnum)) 21 22 ;; 8 23 9 24 (definetype entropysource (struct entropysource)) … … 22 37 (definetype numberfunction (> number)) 23 38 24 ;FIXME cannot restrict number domain w/ type system25 26 39 (definetype randomintegerfunction (number > number)) 27 40 41 (definetype randomf64function (> float)) 42 28 43 ;fortran "real" 29 (definetype randomrealfunction (> float))44 (definetype randomrealfunction randomf64function) 30 45 31 46 (definetype randomu8function (> fixnum)) 32 33 (definetype randomf64function (> float))34 47 35 48 (definetype randomu8vectorfunction (fixnum > u8vector)) 
release/4/srfi27/trunk/srfi27numbers.scm
r35486 r35489 126 126 ; +inf) 127 127 128 (: randompower (procedure * number fullinteger fixnum > fullnumber)) 129 ; 128 130 (define (randompower rndint state precmax m k) ;n = m^k, k >= 1 129 ( do ((k k (fx k 1))130 (n131 (inexact>exact (rndint state precmax))132 ( + (inexact>exact (rndint state precmax)) (* n m))) )133 ((fx= 1 k) n) ) )131 (let ( 132 (rnd (lambda () (inexact>exact (rndint state precmax)))) ) 133 (do ((k k (fx k 1)) 134 (n (rnd) (+ (rnd) (* n m))) ) 135 ((fx= 1 k) n) ) ) ) 134 136 135 137 ; Large Integers … … 141 143 ; uniformly from the range {0..n1}. 142 144 145 (: randomlargeinteger (procedure * number fullinteger fullinteger > fullnumber)) 146 ; 143 147 (define (randomlargeinteger rndint state precmax m n) ;n > m 144 148 (do ((k 2 (fx+ k 1)) 145 149 (mk (* m m) (* mk m))) 146 150 ((<= n mk) 147 (let* ((mkbyn (quotient mk n)) 148 (a (* mkbyn n)) ) 151 (let* ( 152 (mkbyn (quotient mk n)) 153 (a (* mkbyn n)) ) 149 154 (let loop () 150 (let ((x (randompower rndint state precmax m k))) 155 (let ( 156 (x (randompower rndint state precmax m k)) ) 151 157 (if (< x a) 152 158 (quotient x mkbyn) … … 162 168 ; Scheme system, this can be improved. 163 169 170 (: randomlargeinteger (procedure * number fullinteger number > fullnumber)) 171 ; 164 172 (define (randomlargereal rndint state precmax m prec) 165 173 (do ((k 1 (fx+ k 1)) … … 173 181 ;;; 174 182 183 (: nativerealprecision? ((or boolean number) number > boolean)) 184 ; 175 185 (define (nativerealprecision? prec precmax) 176 186 (or
Note: See TracChangeset
for help on using the changeset viewer.