[plt-scheme] flonums question

From: Jos Koot (jos.koot at telefonica.net)
Date: Sat Jan 16 15:50:15 EST 2010

#lang scheme

; I do not understand the difference between the following two:

(let loop ((x 0))
 (let ((d (- 1.0 (+ 1.0 (expt 2 x)))))
  (if (= d 0) x
   ; d is an inexact real number.
   ; well, all reals are inexact I think.
   ; an exact real would have to be an exact ranional, is it not?
   (loop (sub1 x))))) ; --> 54
; flonum arithmetic I think.

(let loop ((x 0))
 (let ((d (exact->inexact (- 1 (+ 1 (expt 2 x))))))
  ; d is an inexact rational number.
  (if (= d 0) x
   (loop (sub1 x))))) ; --> -1075
; where does this high though finite precision come from?

This is with:
Welcome to DrScheme, version 4.2.3.12-svn16jan2010 [3m].
Language: Module custom; memory limit: 800 megabytes.

I cannot make head or tail of it.

Thanks, Jos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20100116/1f0a220f/attachment.html>

Posted on the users mailing list.