aboutsummaryrefslogtreecommitdiffhomepage
path: root/TOOLS
diff options
context:
space:
mode:
authorGravatar Diogo Franco (Kovensky) <diogomfranco@gmail.com>2014-02-15 19:38:32 -0300
committerGravatar Diogo Franco (Kovensky) <diogomfranco@gmail.com>2014-02-15 19:43:22 -0300
commit4a66fce7d336e96847acf5f54e7c0aa30f31ff3b (patch)
treef8f6fb4eb40c52f57aff7d36d906da0005646dad /TOOLS
parent99e38aee9aa52c9a06772d2a6bd5e5bdf17ebc79 (diff)
Parse::Matroska::Reader: get rid of `bigrat`
It seems that it was causing issues with certain perl setups (such as the one on issue #549). It also turns out that it was not behaving correctly (not all constants were being promoted to big nums as they should), so we use explicit objects to derive the constants. There were also precedence issues. I wonder if this even worked right to begin with. The 'double' path (8-byte floats) is untested, as I couldn't easily find a file with such a field. Closes #549.
Diffstat (limited to 'TOOLS')
-rw-r--r--TOOLS/lib/Parse/Matroska/Reader.pm37
1 files changed, 20 insertions, 17 deletions
diff --git a/TOOLS/lib/Parse/Matroska/Reader.pm b/TOOLS/lib/Parse/Matroska/Reader.pm
index 47e67ce5f7..614b7b12c0 100644
--- a/TOOLS/lib/Parse/Matroska/Reader.pm
+++ b/TOOLS/lib/Parse/Matroska/Reader.pm
@@ -132,7 +132,8 @@ sub _bin2int($) {
# creates a floating-point number with the given mantissa and exponent
sub _ldexp {
my ($mantissa, $exponent) = @_;
- return $mantissa * Math::BigRat->new(2)**$exponent;
+ my $r = new Math::BigRat($mantissa);
+ return $r * Math::BigRat->new(2)**$exponent;
}
# NOTE: the read_* functions are hard to read because they're ports
@@ -252,25 +253,27 @@ bytes from the internal filehandle.
Only lengths C<4> and C<8> are supported (C C<float> and C<double>).
=cut
-sub read_float {
- my ($self, $length) = @_;
- my $i = $self->read_uint($length);
- my $f;
+{
+ my $b1 = new Math::BigInt 1;
- use bigrat try => BIGINT_TRY;
+ sub read_float {
+ my ($self, $length) = @_;
+ my $i = new Math::BigInt $self->read_uint($length)->bstr;
+ my $f;
+
+ # These evil expressions reinterpret an unsigned int as IEEE binary floats
+ if ($length == 4) {
+ $f = _ldexp(($i & ((1<<23) - 1)) + (1<<23), ($i>>23 & ((1<<8) - 1)) - 150);
+ $f = -$f if $i & ($b1<<31);
+ } elsif ($length == 8) {
+ $f = _ldexp(($i & (($b1<<52) - 1)) + ($b1<<52), ($i>>52 & ((1<<12) - 1)) - 1075);
+ $f = -$f if $i & ($b1<<63);
+ } else {
+ croak "Matroska Syntax error: unsupported IEEE float byte size $length";
+ }
- # These evil expressions reinterpret an unsigned int as IEEE binary floats
- if ($length == 4) {
- $f = _ldexp(($i & (1<<23 - 1)) + (1<<23), ($i>>23 & (1<<8 - 1)) - 150);
- $f = -$f if $i & (1<<31);
- } elsif ($length == 8) {
- $f = _ldexp(($i & (1<<52 - 1)) + (1<<52), ($i>>52 & (1<<12 - 1)) - 1075);
- $f = -$f if $i & (1<<63);
- } else {
- croak "Matroska Syntax error: unsupported IEEE float byte size $length";
+ return $f;
}
-
- return $f;
}
=method read_ebml_id($length)