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

transitive arithmetic comparisons



    Jinx:
    ...Comparisons between exact and
    inexact numbers should coerce the exact numbers to inexact...

  Alan:
  If <= is to behave transitively, even on inexact arguments, then you have
  to coerce inexact number to exact numbers in order to perform comparisons.

It depends on the implementation.  Fortunately this is of no concern to the
user, who can rest easy knowing that the arithmetic predicates are transitive
without having to know what the implementors had to go through to make them
so.

In an implementation that represents all exact reals as 32-bit fixnums, and
all inexact reals as 64-bit flonums, then it is correct to coerce exact to
inexact before comparing, as Jinx said.

In an implementation that represents all exact reals as fixnums, bignums, or
ratnums, and all inexact reals as flonums, then it is correct to coerce
inexact to exact before comparing, as Alan said.

In an implementation that represents all exact reals as 32-bit fixnums, and
all inexact reals as 32-bit flonums, then the correct behavior is much more
complicated because there exist fixnums that cannot be coerced to flonums
without loss of accuracy and vice versa.  Likewise for implementations that
represent all exact reals as fixnums or bignums, and all inexact reals as
flonums.  Although algorithms with the correct transitive behavior are a
bit too complicated for me to want to describe here, they exist.

The R4RS specifies only that the arithmetic predicates must be transitive.
It doesn't say how this is to be achieved, since that would require some
assumptions about the particular representations used for exact and inexact
numbers.

Peace, Will