mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 14:19:18 +02:00
Reducing floating point errors in iota.
This commit is contained in:
parent
a81004672d
commit
944561b4da
1 changed files with 3 additions and 4 deletions
|
@ -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))))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue