Compare commits

...

2 Commits

Author SHA1 Message Date
Nikolay Puzanov
19a7b4a287 Add round-to function 2022-11-06 14:23:18 +03:00
Nikolay Puzanov
f4d29094c9 Weight in random constraints now is not limited by 1 2022-11-06 14:22:30 +03:00
2 changed files with 12 additions and 10 deletions

View File

@ -5,7 +5,7 @@
(import (srfi srfi-1)
(srfi srfi-60))
(export log2 clog2
(export log2 clog2 round-to
one? power-of-two?
curry curry-r
transpose
@ -36,6 +36,11 @@
;;; Check for (x == 1)
(define (one? x) (= x 1))
;;; Round to the 'n' decimal place
(define (round-to n num)
(let ((k (expt 10 n)))
(/ (round (* num k)) k)))
;;; Currying
;;; Example: ((curry-r f 1) 2 3) -> (f 1 2 3)
(define (curry f . args)

View File

@ -8,7 +8,7 @@
;;;
;;; Remove redundant (zero range) constraints.
;;; Limit weight in range (0..1]
;;; Limit the weight value in positive range
;;;
(define (clean-constraints constrs)
(remove (lambda (c)
@ -20,14 +20,11 @@
(map (lambda (c)
(let ((from (inexact->exact (round (car c))))
(to (inexact->exact (round (cadr c))))
(w (caddr c)))
(let ((w (cond
((< w 0) 0)
((> w 1) 1)
(else w))))
(if (> from to)
(list to from w)
(list from to w)))))
(w (let ((w (caddr c)))
(if (< w 0) 0 w))))
(if (> from to)
(list to from w)
(list from to w))))
constrs)))
;;;
;;; Make constrained random number generator.