Skip Menu |

This queue is for tickets about the Data-SecsPack CPAN distribution.

Report information
The Basics
Id: 32346
Status: new
Priority: 0/
Queue: Data-SecsPack

People
Owner: Nobody in particular
Requestors: darth.jonathon [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: unpack_float: $decimal_magnitude not handled correctly
Whenever $decimal_magnitude is supposed to start with a zero, the leading zeros are omitted. A possible fix is to use sprintf to pad the number with leading zeros: sub unpack_float { ... if($binary_magnitude) { $decimal_magnitude = $binary_magnitude . '0'x20; # twenty digit decimal results $dm = $decimal_magnitude/$binary_divider; $decimal_magnitude = Math::BigInt->new($decimal_magnitude)->bdiv($binary_divider)->bstr(); ### FIX: ADD FOLLOWING BLOCK ### if (length($decimal_magnitude) < 20) { $decimal_magnitude = sprintf "%.20d", $decimal_magnitude; } ### FIX: END OF BLOCK ### } else { $decimal_magnitude = 0; } ... }
From: darth.jonathon [...] gmail.com
One test case is: $f[0]=32415; $f[1]=-5; ($format, $tbit) = pack_float( "F4", \@f); $f1 = unpack_float( "F4", $tbit ); Also, float2binary/ifloat2binary may have a similar problem. I'm not sure, but it should be checked. On Wed Jan 16 02:08:59 2008, johndarth wrote: Show quoted text
> Whenever $decimal_magnitude is supposed to start with a zero, the > leading zeros are omitted. A possible fix is to use sprintf to pad the > number with leading zeros: > > sub unpack_float > { > ... > if($binary_magnitude) { > $decimal_magnitude = $binary_magnitude . '0'x20; # twenty digit > decimal results > $dm = $decimal_magnitude/$binary_divider; > $decimal_magnitude = > Math::BigInt->new($decimal_magnitude)->bdiv($binary_divider)->bstr(); > > ### FIX: ADD FOLLOWING BLOCK ### > if (length($decimal_magnitude) < 20) { > $decimal_magnitude = sprintf "%.20d", $decimal_magnitude; > } > ### FIX: END OF BLOCK ### > > } > else { > $decimal_magnitude = 0; > } > ... > }