guile-user
[Top][All Lists]
Advanced

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

Re: (real? (* +i +i)) -> #f


From: Mark H Weaver
Subject: Re: (real? (* +i +i)) -> #f
Date: Tue, 07 Aug 2012 15:04:13 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.5) Gecko/20120624 Icedove/10.0.5

On 08/03/2012 06:02 AM, JihemD wrote:
I am playing around with Guile 2.05 on Kubuntu 12.04,
why :
scheme@(guile-user)>  (real? (* +i +i))
$13 = #f
but :
scheme@(guile-user)>  (zero? (imag-part (* +i +i)))
$14 = #t

In recent Scheme standards (both R6RS and draft R7RS), a number is considered real if and only if the imaginary part is an _exact_ zero. See the definitions of 'real?' in R6RS section 11.7.4 and R7RS section 6.2.6. The R6RS Rationale document provides some discussion in the "Flow analysis" portion of section 11.6.6.

The R6RS provides a 'real-valued?' predicate that might be closer to what you expect. You can get it in Guile by importing (rnrs base).

As Ian noted, Guile does not currently support exact non-real complex numbers, so +i cannot be represented exactly, and thus the imaginary part of +i^2 is not known to be exactly zero. If we add support for exact non-real complex numbers some day, then (real? (* +i +i)) will become #t.

Thx Ian, the concept of exactness is new for me

The concept of exact numbers is described in R6RS section 3.2.

     Mark



reply via email to

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