seanjensengrey / mosh-scheme

Automatically exported from code.google.com/p/mosh-scheme
Other
0 stars 0 forks source link

exact-integer-sqrt shoud raise an error when an inexact integer given #154

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
$ mosh -V
Mosh R6RS scheme interpreter, version 0.2.5
$ mos
mosh> (exact? 0.0)
#f
mosh> (exact-integer-sqrt 0.0)
0
mosh> 

What is the expected output? What do you see instead?
As http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_idx_562 ,
exact-integer-sqrt accepts an exact non-negative integer.

Original issue reported on code.google.com by tabe.fix...@gmail.com on 19 Jun 2010 at 3:20

GoogleCodeExporter commented 9 years ago
A patch for this can be like:

diff --git a/boot/baselib/misc.scm b/boot/baselib/misc.scm
index bf5f60e..6318f89 100644
--- a/boot/baselib/misc.scm
+++ b/boot/baselib/misc.scm
@@ -3,8 +3,8 @@
            (map string->list str2)))

 (define (exact-integer-sqrt k)
-  (unless (and (integer? k) (>= k 0))
-    (assertion-violation 'exact-integer-sqrt "exact integer number required" 
(list k)))
+  (unless (and (integer? k) (exact? k) (>= k 0))
+    (assertion-violation 'exact-integer-sqrt "exact non-negative integer 
required" (list k)))
   (let* ([s (exact (truncate (sqrt k)))]
          [r (- k (* s s))])
     (values s r)))

Original comment by tabe.fix...@gmail.com on 19 Jun 2010 at 4:09

GoogleCodeExporter commented 9 years ago
Thanks. Fixed.

Original comment by hige...@gmail.com on 20 Jun 2010 at 7:14

GoogleCodeExporter commented 9 years ago
I think the following fix lacks the exactness check:
http://github.com/higepon/mosh/commit/4f1b3c208311211f18dec2e99448c387cfc1630f

Original comment by tabe.fix...@gmail.com on 21 Jun 2010 at 2:05

GoogleCodeExporter commented 9 years ago
You're right about this.
Fixed. Thanks.

Original comment by hige...@gmail.com on 22 Jun 2010 at 12:58