Reducing floating point errors in iota.

This commit is contained in:
Alex Shinn 2012-01-04 15:11:12 +09:00
parent a81004672d
commit 944561b4da

View file

@ -1,5 +1,5 @@
;; constructors.scm -- list construction utilities ;; constructors.scm -- list construction utilities
;; Copyright (c) 2009 Alex Shinn. All rights reserved. ;; Copyright (c) 2009-2012 Alex Shinn. All rights reserved.
;; BSD-style license: http://synthcode.com/license.txt ;; BSD-style license: http://synthcode.com/license.txt
(define (xcons a b) (cons b a)) (define (xcons a b) (cons b a))
@ -29,8 +29,7 @@
(define (iota count . o) (define (iota count . o)
(let ((start (if (pair? o) (car o) 0)) (let ((start (if (pair? o) (car o) 0))
(step (if (and (pair? o) (pair? (cdr o))) (cadr o) 1))) (step (if (and (pair? o) (pair? (cdr o))) (cadr o) 1)))
(let lp ((i count) (n (+ start (* (- count 1) step))) (res '())) (let lp ((i count) (res '()))
(if (<= i 0) (if (<= i 0)
res res
(lp (- i 1) (- n step) (cons n res)))))) (lp (- i 1) (cons (+ start (* (- i 1) step)) res))))))