#!/usr/local/bin/perl -w

use strict ;

use constant BIG_ENDIAN => pack('N', 1) eq pack('L', 1) ;
use constant FLOAT_LEN => length pack "d", 1 ;
use constant INT_LEN => length pack "N", 1 ;
use constant INT_BIT_LEN => INT_LEN * 8 ;
use constant FLOAT_PACK => BIG_ENDIAN ?
		q{pack( 'd', $val )} :
		q{reverse( pack( 'd', $val ) )} ;

# xor masks to normalize negative and positive floats
my $xor_neg = "\xFF" x FLOAT_LEN ;

# this only flips the sign bit (it gets extended by null bytes in the ^ op)
my $xor_pos = "\x80" ;



sub foo {
        my $rec_ind = 0 ;

        return  @_[
            map unpack( 'N', substr( $_, -4 ) ), 
            sort
            map pack( "A8N",
                do{ my ($val) = $_ ; print "VAL [$val]\n" ; ( $val < 0 ? $xor_neg : $xor_pos ) ^ pack( 'd', $val ) },
                $rec_ind++
            ), @_
        ] ;
}

foo( 1, 4, -2 ) ;

