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

Re: decimal to binary?

Thread Previous | Thread Next
From:
Uri Guttman
Date:
September 23, 2009 13:49
Subject:
Re: decimal to binary?
Message ID:
87k4zpqtde.fsf@quad.sysarch.com
>>>>> "BM" == Bob McConnell <rvm@CBORD.com> writes:

  BM> OK, that I can understand. However, I don't see where that was
  BM> expressed or implied in the original query. Are you assuming that
  BM> every current architecture and Perl implementation uses that
  BM> format to store double precision numbers? Is that a safe
  BM> assumption?

ieee float format is about the only way anyone does floats today. but
pack actually doesn't even care about the float format. it just copies
the internal float to a place where it can be accessed as a string of
bytes (the string slot in the scalar). you can take any byte string you
want and unpack back into the float slot. the only restriction is the
size and that is usually 8 bytes (a double which is perl's standard
float size). pack supports single precision (4 bytes) as well as long
doubles if your machine supports them.

as for whether this is what the OP wanted, note that he since posted
that he is reading perlpacktut for his answers. someone else already
posted the pack format needed but i wanted him to rtfm and learn more
about pack.

uri

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