On Mon, Jul 15, 2002 at 10:17:51PM -0700, John Porter wrote:
> 
> Sean O'Rourke wrote:
> > ... all it buys you is a few bits of precision when your ints
> > and floats are both 64-bit, and slower comparisons all the time.
> > IMHO it's a wash, so I did it this way.
> 
> I would point out that integers have infinite precision.
> More than a few bits' difference, I'd say.
> 
> But you're right.  As long as the conversion from int to float
> is done just before the comparison -- i.e. no intervening
> floating-point ops on the numbers -- then the result of
> comparison should always be right, no precision issue.
> (I'm just talking about in the int-vs-int case.)
> So, never mind. :-)

I'm confused. For some values of 64 bit integers, given 64 bit doubles,
the comparison is not correct when both are converted to doubles:

perl5.6.1-64 -le '$a = ~0; $b = $a & ~1; printf "%x <=> %x\n", $a, $b; print $a <=> 
$b; {use integer; print $a <=> $b}'
ffffffffffffffff <=> fffffffffffffffe
0
1

5.8.0 does the full fun and games of integer or floating point comparison:

perl5.8.0-64 -le '$a = ~0; $b = $a & ~1; printf "%x <=> %x\n", $a, $b; print $a <=> 
$b; {use integer; print $a <=> $b}'
ffffffffffffffff <=> fffffffffffffffe
1
1

IIRC the speed difference was hard to benchmark. However, the ability to
deal with large file offsets, windows device numbers and other 64 bit
quantities correctly was seen as useful.

I presume multimethod dispatch will render this discussion obsolete.

Nicholas Clark

Reply via email to