1 #!/usr/local/bin/perl -w
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 ) )} ;
13 # xor masks to normalize negative and positive floats
14 my $xor_neg = "\xFF" x FLOAT_LEN ;
16 # this only flips the sign bit (it gets extended by null bytes in the ^ op)
17 my $xor_pos = "\x80" ;
25 map unpack( 'N', substr( $_, -4 ) ),
28 do{ my ($val) = $_ ; print "VAL [$val]\n" ; ( $val < 0 ? $xor_neg : $xor_pos ) ^ pack( 'd', $val ) },