467,179 Members | 1,228 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,179 developers. It's quick & easy.

Floating point internal representation..

In perl, how can I get the actual internal floating point data for a variable? In C, I can do something like this
Expand|Select|Wrap|Line Numbers
  1. {
  2.     float f = 5.88;
  4.     unsigned char a[4];
  6.     memcpy(a, (void *)&f, 4)
  8.     printf("0x%x  %x  %x  %x\n", a[3], a[2], a[1], a[0]);
  9. }
This prints "0x40 bc 28 f6" -> the IEEE floating point representation for 5.88..

I need to do the same with a statement like

my $f = 5.88;

Jun 27 '08 #1
  • viewed: 1512
1 Reply
Well, that was as clear as mud, but it looks like the answer is to pack/unpack.

Expand|Select|Wrap|Line Numbers
  1.     my $f = 5.88;
  2.     unpack('L', pack('f',  $f));
Jun 27 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Benedikt Wismans | last post: by
21 posts views Thread by Allin Cottrell | last post: by
5 posts views Thread by Steffen | last post: by
4 posts views Thread by riya1012@gmail.com | last post: by
70 posts views Thread by Robert Gamble | last post: by
15 posts views Thread by Mukesh_Singh_Nick@yahoo.com | last post: by
39 posts views Thread by rembremading | last post: by
14 posts views Thread by mathieu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.