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

Re: decimal to binary?

Thread Previous | Thread Next
Chas. Owens
September 23, 2009 14:34
Re: decimal to binary?
Message ID:
On Wed, Sep 23, 2009 at 15:53, Bob McConnell <> wrote:
> 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

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
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About