Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Extracting IEEE 754 floating point numbersby jmcnamara (Monsignor) |
on Oct 28, 2002 at 22:49 UTC ( [id://208629]=note: print w/replies, xml ) | Need Help?? |
Unless you have esoteric hardware your platform probably supports IEEE754 floats. The most probable cause of incompatibility is that the MS platform uses a little-endian byte order and your other platform uses a big-endian byte order. Try the following code on both platforms and compare the output: If one is the reverse of the other you can use the following to unpack the float: my $num = unpack "f", reverse $packed_num; One other thing to look out for is that the floating point number might be packed as a 8-byte double and not as a 4-byte float. Finally, as a *last* resort (because I think your problem is elsewhere) here is a function to portably unpack a 4-byte IEEE754 float in little-endian order. This is a port of a C function by Steve Summit from the book "C Unleashed":
--
In Section
Seekers of Perl Wisdom
|
|