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
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;
            }
        }
        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?

/s

Reply via email to