develooper Front page | perl.beginners | Postings from September 2009

Re: decimal to binary?

Thread Previous | Thread Next
From:
Chas. Owens
Date:
September 23, 2009 14:34
Subject:
Re: decimal to binary?
Message ID:
58ce48dc0909231433y4d108c33k8847356468ab16d2@mail.gmail.com
On Wed, Sep 23, 2009 at 15:53, Bob McConnell <rvm@cbord.com> wrote:
snip
> OK, that I can understand. However, I don't see where that was expressed
> or implied in the original query. Are you assuming that every current
> architecture and Perl implementation uses that format to store double
> precision numbers? Is that a safe assumption?
>
> Bob McConnell
snip

No, it is not safe to assume that the value you get from pack will
work on another platform.  The pack function claims that "d" creates a
native-floating point number as a string of bytes.  This means you are
dependent on the native implementations of floating point numbers
being the same between systems.  However, a quick sample of OS X 10.5
(x86), a variety of Linuxes (x86), Win32 (x86), and FreeBsd (x86)
shows that it works across a wide swath of what one generally works
with.  The Power PC machine machine I have access to (running OS X)
works if you reverse the bytes.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

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