What is the function of this use of floating-point arithmetic in PHP?
What is the function of this use of floating-point arithmetic in PHP?
Please take a look at the example of floating point arithmetic in Baidu Encyclopedia first
Http://wenku.baidu.com/view/9ba120a108a1284ac85043d8.html?re=view
The hexadecimal 42c88000.
Use the IEEE754 standard 32-bit floating-point number format to calculate the result equals 100.25
To figure out the hexadecimal c1c90000 is 25.125.
Are there any existing functions?
Write an example for me, thank you very much.
Thank you
------to solve the idea----------------------
function Hextodecfloat ($strHex) {
$v = Hexdec ($strHex);
------to solve the idea----------------------
1);
$exp = ($v >> & 0xFF)-127;
return $x * POW (2, $exp-23);
}
$a = ' 42c88000 ';
echo hextodecfloat ($a);
equals 100.25
------to solve the idea----------------------
$s = ' 42c88000 ';
Echo Current (unpack (' F ', pack (' V ', Hexdec ($s))));
100.25
$s = ' c1c90000 ';
Echo Current (unpack (' F ', pack (' V ', Hexdec ($s))));
-25.125