|
Posted by Kimmo Laine on 06/12/06 10:55
"Kimmo Laine" <spam@outolempi.net> wrote in message
news:8qbjg.1702$Ux1.120@reader1.news.jippii.net...
> <vendredi5h@gmail.com> wrote in message
> news:1149905810.660991.135400@f6g2000cwb.googlegroups.com...
>> Hello all,
>>
>> I'd like to split a 64-bits word (hold as a floating point number) into
>> two 32-bits words (hold as integers). Bitwise operators are working on
>> Integers, not on floating point.
>>
>> Anyone can tell me how I can do this?
>
>
> This is just a guess but manipulating it with pack and unpack just might
> work, something like this:
> print_r(unpack('Lhigh/Llow', pack('d',12.015)));
>
> first pack the 64bit double into a string and then read two 32bit longs
> from the packed string. Just an idea. Altough when I tested it with 12.015
> didn't seem anything like 12 and 015 after unpacking it, so it might not
> work at all but give it a try...
>
I did a little more testing and by golly, it seems actually to be working, I
get the same result out what goes in
$x = unpack('L2long', pack('d',999999.999999));
$y = unpack('ddouble', pack('L2',$x['long1'],$x['long2']));
print_r($x);
print_r($y);
So apparently the pack and it's evil twin sister unpack offer a workaround
for splitting numbers to high and low end.
--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
Navigation:
[Reply to this message]
|