line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::IEEE754; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
27985
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
437
|
use utf8; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
42
|
use Config; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
5
|
use Exporter qw( import ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
341
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
14
|
|
|
|
|
|
|
pack_double_be |
15
|
|
|
|
|
|
|
pack_float_be |
16
|
|
|
|
|
|
|
unpack_double_be |
17
|
|
|
|
|
|
|
unpack_float_be |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# This code is all copied from Data::MessagePack::PP by Makamaka |
21
|
|
|
|
|
|
|
# Hannyaharamitu, and was then tweaked by Dave Rolsky. Blame Dave for the |
22
|
|
|
|
|
|
|
# bugs. |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
# Perl 5.10 introduced the ">" and "<" modifiers for pack which can be used to |
25
|
|
|
|
|
|
|
# force a specific endianness. |
26
|
|
|
|
|
|
|
if ( $] < 5.010 ) { |
27
|
|
|
|
|
|
|
my $bo_is_le = ( $Config{byteorder} =~ /^1234/ ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if ($bo_is_le) { |
30
|
|
|
|
|
|
|
*pack_float_be = sub { |
31
|
|
|
|
|
|
|
return pack( 'N1', unpack( 'V1', pack( 'f', $_[0] ) ) ); |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
*pack_double_be = sub { |
34
|
|
|
|
|
|
|
my @v = unpack( 'V2', pack( 'd', $_[0] ) ); |
35
|
|
|
|
|
|
|
return pack( 'N2', @v[ 1, 0 ] ); |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
*unpack_float_be = sub { |
39
|
|
|
|
|
|
|
my @v = unpack( 'v2', $_[0] ); |
40
|
|
|
|
|
|
|
return unpack( 'f', pack( 'n2', @v[ 1, 0 ] ) ); |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
*unpack_double_be = sub { |
43
|
|
|
|
|
|
|
my @v = unpack( 'V2', $_[0] ); |
44
|
|
|
|
|
|
|
return unpack( 'd', pack( 'N2', @v[ 1, 0 ] ) ); |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
else { # big endian |
48
|
|
|
|
|
|
|
*pack_float_be = sub { |
49
|
|
|
|
|
|
|
return pack 'f', $_[0]; |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
*pack_double_be = sub { |
52
|
|
|
|
|
|
|
return pack 'd', $_[0]; |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
*unpack_float_be |
56
|
|
|
|
|
|
|
= sub { return unpack( 'f', $_[0] ); }; |
57
|
|
|
|
|
|
|
*unpack_double_be |
58
|
|
|
|
|
|
|
= sub { return unpack( 'd', $_[0] ); }; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
|
|
|
|
|
|
*pack_float_be = sub { |
63
|
9
|
|
|
9
|
|
3978
|
return pack 'f>', $_[0]; |
64
|
|
|
|
|
|
|
}; |
65
|
|
|
|
|
|
|
*pack_double_be = sub { |
66
|
14
|
|
|
14
|
|
7048
|
return pack 'd>', $_[0]; |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
*unpack_float_be = sub { |
70
|
9
|
|
|
9
|
|
83
|
return unpack( 'f>', $_[0] ); |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
*unpack_double_be = sub { |
73
|
14
|
|
|
14
|
|
119
|
return unpack( 'd>', $_[0] ); |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# ABSTRACT: Pack and unpack big-endian IEEE754 floats and doubles |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
__END__ |