By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,778 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,778 IT Pros & Developers. It's quick & easy.

Floating point internal representation..

P: 2
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;
  3.  
  4.     unsigned char a[4];
  5.  
  6.     memcpy(a, (void *)&f, 4)
  7.  
  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;

Thanks,
Doug
Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: 2
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.