guile-user
[Top][All Lists]
Advanced

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

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


From: Ian Price
Subject: Re: (real? (* +i +i)) -> #f
Date: Fri, 03 Aug 2012 11:33:25 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

JihemD <address@hidden> writes:

> Hi
> 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
>
> thxs

I believe guile only considers numbers with an _exact_ 0 imaginary part
to be real. However, since all guile complex numbers are inexact, this
means that (* +i +i) is not considered real.

scheme@(guile−user)> (* +i +i)
$19 = −1.0+0.0i
scheme@(guile−user)> (exact? (imag-part $19))
$20 = #f

While I don't know if this was a specific concern when writing, this is
in line with the interpretation in section 11.7.4  Numerical operations
of the r6rs document.

http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-14.html#node_sec_11.7.4.1

If x is a real number object, then (rational? x) is true if and only if
there exist exact integer objects k1 and k2 such that (= x (/ k1 k2))
and (= (numerator x) k1) and (= (denominator x) k2) are all true. Thus
infinities and NaNs are not rational number objects.

(real? -2.5+0.0i)                              ⇒  #f
(real? -2.5+0i)                                ⇒  #t

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



reply via email to

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