Commit | Line | Data |
7468c584 |
1 | #!/usr/local/bin/perl -w |
2 | |
3 | use strict ; |
4 | |
5 | use constant BIG_ENDIAN => pack('N', 1) eq pack('L', 1) ; |
6 | use constant FLOAT_LEN => length pack "d", 1 ; |
7 | use constant INT_LEN => length pack "N", 1 ; |
8 | use constant INT_BIT_LEN => INT_LEN * 8 ; |
9 | use constant FLOAT_PACK => BIG_ENDIAN ? |
10 | q{pack( 'd', $val )} : |
11 | q{reverse( pack( 'd', $val ) )} ; |
12 | |
13 | # xor masks to normalize negative and positive floats |
14 | my $xor_neg = "\xFF" x FLOAT_LEN ; |
15 | |
16 | # this only flips the sign bit (it gets extended by null bytes in the ^ op) |
17 | my $xor_pos = "\x80" ; |
18 | |
19 | |
20 | |
21 | sub foo { |
22 | my $rec_ind = 0 ; |
23 | |
24 | return @_[ |
25 | map unpack( 'N', substr( $_, -4 ) ), |
26 | sort |
27 | map pack( "A8N", |
28 | do{ my ($val) = $_ ; print "VAL [$val]\n" ; ( $val < 0 ? $xor_neg : $xor_pos ) ^ pack( 'd', $val ) }, |
29 | $rec_ind++ |
30 | ), @_ |
31 | ] ; |
32 | } |
33 | |
34 | foo( 1, 4, -2 ) ; |
35 | |