This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Float syntax


On 01/24/2011 11:11 PM, Helmut Eller wrote:
* Per Bothner [2011-01-25 02:34] writes:

(= java.lang.Double:POSITIVE_INFINITY
     java.lang.Float:POSITIVE_INFINITY) =>   #t
(equal? java.lang.Double:POSITIVE_INFINITY
          java.lang.Float:POSITIVE_INFINITY) =>   #f

I think the other ones are correct. I added them all to num-test.scm.

Shouldn't (= x y) => #t imply (equal? x y) => #t ? At least I always assumed that equal? and eqv? use = to compare numbers.

Not according to my reading of R6RS. First, equal? applied to numbers is defined as eqv?. But eqv? is not defined as =. = is defined as numerically equal, so:

(= 1 1.0) ==> #t
(= +nan.0 +nan.0) ==> #f

eqv? on numbers is (roughly defined) as "operationally equivalent"
or "functionally indistinguishable".  Thus:

(eqv? 1 1.0) ==> #f
(eqv? +nan.0 +nan.0) ==> #t

R6RS is explicit that an exact and an inexact number cannot be eqv?
R6RS doesn't discuss multiple floating-point representations, but I
think the correct semantics is that floats of different precisions
are never eqv?.  It's somewhat unspecified, since the actual definition is
that (eqv? Obj1 Obj2) returns #t if:

  Obj1 and obj2 are both inexact number objects, are
  numerically equal (see =, section 11.7), and yield the
  same results (in the sense of eqv?) when passed as
  arguments to any other procedure that can be defined as
  a finite composition of Schemeâs standard arithmetic
  procedures.

and return #f when:
  Obj1 and obj2 yield different results (in the sense of
  eqv?) when passed as arguments to any other procedure
  that can be defined as a finite composition of
  Schemeâs standard arithmetic procedures.

Regardless, the "spirit of eqv?" to me says the result should
be #f when the precisions are different.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]