On Tue, Jul 16, 2002 at 07:42:25AM -0700, Sean O'Rourke wrote: > On Tue, 16 Jul 2002, Nicholas Clark wrote: > > > 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. > > Let's not lose sight of the forest for the trees here -- the comparisons > are now *backwards*, which is considerably worse than imprecise. Here's
I had. I didn't realise that this was the current situation. > what I think the multimethod dispatch version would look like, without the > automatic multimethod dispatch: > > INTVAL cmp (PMC* value) { > if (value->vtable == &Parrot_base_vtables[enum_class_PerlString]) { > FLOATVAL fdiff = (FLOATVAL)self->cache.int_val > - value->vtable->get_number(INTERP, value); > if (fdiff == 0) { > INTVAL idiff = SELF->cache.int_val > - value->vtable->get_integer(INTERP, value); > return idiff > 0 ? 1 : diff < 0 ? -1 : 0; > } else { > return fdiff > 0 ? 1 : -1; > } When we get back to worrying about the details, I think NaNs are going to return -1. I'm not sure if this is a huge concern yet, although it could get confusing if A cmp B is -1, and so is B cmp A. > } > else if (value->vtable == &Parrot_base_vtables[enum_class_PerlNum]) { > FLOATVAL diff; > diff = (FLOATVAL)SELF->cache.int_val > - value->vtable->get_number(INTERP, value); > return diff > 0 ? 1 : diff < 0 ? -1 : 0; > } > else { > /* int or indef */ > INTVAL diff = SELF->cache.int_val > - value->vtable->get_integer(INTERP, value); > return diff > 0 ? 1 : diff < 0 ? -1 : 0; > } > } > > Why not drop something like this in for the moment, then take another look > when we have multimethods? Putting in something that works well enough, and flagging it for a revisit later seems like a very good solution. Nicholas Clark -- Even better than the real thing: http://nms-cgi.sourceforge.net/