Changeset 35489 in project


Ignore:
Timestamp:
04/30/18 00:03:10 (4 months ago)
Author:
kon
Message:

add numbers types

Location:
release/4/srfi-27/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/srfi-27/trunk/srfi-27-common-types.scm

    r35485 r35489  
    44;; Issues
    55;;
     6;; - cannot restrict number domain w/ type system
     7
     8;;
    69
    710(define-type alist list)
     11
     12;;
     13
     14(define-type bignum (struct bignum))
     15(define-type ratnum (struct ratnum))
     16(define-type compnum (struct compnum))
     17
     18(define-type full-integer (or fixnum number bignum))  ;close (;-)
     19
     20(define-type full-number (or fixnum float number bignum ratnum compnum))
     21
     22;;
    823
    924(define-type entropy-source (struct entropy-source))
     
    2237(define-type number-function (--> number))
    2338
    24 ;FIXME cannot restrict number domain w/ type system
    25 
    2639(define-type random-integer-function (number --> number))
    2740
     41(define-type random-f64-function  (--> float))
     42
    2843;fortran "real"
    29 (define-type random-real-function (--> float))
     44(define-type random-real-function random-f64-function)
    3045
    3146(define-type random-u8-function  (--> fixnum))
    32 
    33 (define-type random-f64-function  (--> float))
    3447
    3548(define-type random-u8vector-function (fixnum --> u8vector))
  • release/4/srfi-27/trunk/srfi-27-numbers.scm

    r35486 r35489  
    126126; +inf)
    127127
     128(: random-power (procedure * number full-integer fixnum --> full-number))
     129;
    128130(define (random-power rndint state prec-max m k) ;n = m^k, k >= 1
    129   (do ((k k (fx- k 1))
    130        (n
    131          (inexact->exact (rndint state prec-max))
    132          (+ (inexact->exact (rndint state prec-max)) (* n m))) )
    133       ((fx= 1 k) n) ) )
     131  (let (
     132    (rnd (lambda () (inexact->exact (rndint state prec-max)))) )
     133    (do ((k k (fx- k 1))
     134         (n (rnd) (+ (rnd) (* n m))) )
     135        ((fx= 1 k) n) ) ) )
    134136
    135137; Large Integers
     
    141143; uniformly from the range {0..n-1}.
    142144
     145(: random-large-integer (procedure * number full-integer full-integer --> full-number))
     146;
    143147(define (random-large-integer rndint state prec-max m n) ;n > m
    144148  (do ((k 2 (fx+ k 1))
    145149       (mk (* m m) (* mk m)))
    146150      ((<= n mk)
    147         (let* ((mk-by-n (quotient mk n))
    148                (a (* mk-by-n n)) )
     151        (let* (
     152          (mk-by-n (quotient mk n))
     153          (a (* mk-by-n n)) )
    149154          (let loop ()
    150             (let ((x (random-power rndint state prec-max m k)))
     155            (let (
     156              (x (random-power rndint state prec-max m k)) )
    151157              (if (< x a)
    152158                (quotient x mk-by-n)
     
    162168; Scheme system, this can be improved.
    163169
     170(: random-large-integer (procedure * number full-integer number --> full-number))
     171;
    164172(define (random-large-real rndint state prec-max m prec)
    165173  (do ((k 1 (fx+ k 1))
     
    173181;;;
    174182
     183(: native-real-precision? ((or boolean number) number --> boolean))
     184;
    175185(define (native-real-precision? prec prec-max)
    176186  (or
Note: See TracChangeset for help on using the changeset viewer.