develooper Front page | perl.perl5.porters | Postings from October 2013

Re: [perl #120405] Wrong results for unpack "f"

Thread Previous | Thread Next
From:
Lukas Mai
Date:
October 29, 2013 09:06
Subject:
Re: [perl #120405] Wrong results for unpack "f"
Message ID:
526F7A96.4060905@gmail.com
On 29.10.2013 10:00, slaven@rezic.de (via RT) wrote:
> # New Ticket Created by  slaven@rezic.de 
> # Please include the string:  [perl #120405]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=120405 >
> 
> 
> The problem is described in the StackOverflow article http://stackoverflow.com/questions/18969702/perl-strange-behaviour-on-unpack-of-floating-value

Short version (copied into this bug for easier access):
-----------------------------------------------------------------------

$ perl -e "print unpack('f>', pack ('f>', 279.117156982422));"
279.617156982422

Definitely a bug in Perl's unpacking. It has difficulty in handling
floats in the binary form xxxxyyFF at least in a 32-bit platform, where
80 <= yy <= BF. The packed result will become xxxxzzFF, where zz = yy +
40 (all in hexadecimal). And this is not a problem of endianness, as you
could see here:

$ perl -e "print unpack('H8', pack ('f', unpack('f', pack('H8',
'000088ff'))));";
0000c8ff

-----------------------------------------------------------------------
-- 
Lukas Mai <plokinom@gmail.com>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About