chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] read / write floats


From: Kon Lovett
Subject: Re: [Chicken-users] read / write floats
Date: Sat, 25 Aug 2007 15:14:27 -0700


On Aug 25, 2007, at 1:44 PM, Gábor Balázs wrote:

Hello,

I tried the following with chicken 2.6:

    (define v1 (/ 1 3))
    (call-with-output-file "try.dat"
                           (lambda (port)
                             (write v1 port)))
                           
    (define v2 (call-with-input-file "try.dat"
                                     (lambda (port)
                                       (read port))))
    (print "v1 = " v1)
    (print "v2 = " v2)
    (print (equal? v1 v2))
   
(print (= v1 v2))
    (print (- v1 v2))

And the result was:

    v1 = 0.333333333333333
    v2 = 0.333333333333333
    #f
    #f
    3.33066907387547e-16

Is it a known bug?

Yes. See http://galinha.ucpel.tche.br/Deviations%20from%20the%20standard [6.6.4]

This is real "gotcha" in core Chicken. See the " numbers" egg.

$ csi

this is CHICKEN
Version 2.637 - macosx-unix-gnu-ppc - [ manyargs dload ptables extraslot applyhook autotools ]
(c)2000-2007 Felix L. Winkelmann
; loading /Users/klovett/.csirc ...
#;1> (use numbers)
; loading /usr/local/lib/chicken/1x/numbers.scm ...
; loading /usr/local/lib/chicken/1x/numbers-base.so ...
#;2> (define v1 (/ 1 3))
    (call-with-output-file "try.dat"
                           (lambda (port)
                             (write v1 port)))
                           
    (define v2 (call-with-input-file "try.dat"
                                     (lambda (port)
                                       (read port))))
    (print "v1 = " v1)
    (print "v2 = " v2)
    (print (equal? v1 v2))
    (print (= v1 v2))
    (print (- v1 v2)) #;3> #;4> #;5> v1 = 1/3
"v1 = "
#;6> v2 = 1/3
"v2 = "
#;7> #t
#t
#;8> #t
#t
#;9>

However , this only works because the 'v' values are exact! '(define v1 (exact->inexact (/ 1 3)))' still has the read/write invariance problem.

I tried to report this, but I did not find the easy way.



`bg`

_______________________________________________
Chicken-users mailing list


reply via email to

[Prev in Thread] Current Thread [Next in Thread]