summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>2014-02-15 19:38:32 -0300
committerwm4 <wm4@nowhere>2014-03-11 00:08:57 +0100
commit6d9d597b10f968906f5964202f1866b379d1ad97 (patch)
treeef1e15b4085d70bf2f1952fe826d28d2e33ab460
parentc4d905b567fa9f56001696086383d57f40f14fab (diff)
downloadmpv-6d9d597b10f968906f5964202f1866b379d1ad97.tar.bz2
mpv-6d9d597b10f968906f5964202f1866b379d1ad97.tar.xz
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.
-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)