In php, what is the floating point operation function used in php?
Please take a look at the floating point operation examples in Baidu Encyclopedia.
Http://wenku.baidu.com/view/9ba120a108a1284ac85043d8.html? Re = view
That is, the hexadecimal 42C88000
The result is equivalent to 100.25 in the IEEE754 standard 32-bit floating point format.
Calculate the hexadecimal C1C90000 value as-25.125.
Are there ready-made functions?
I am very grateful for writing an example for me.
Thank you.
Reply to discussion (solution)
function hexToDecFloat($strHex) {$v = hexdec($strHex);$x = ($v & ((1 << 23) - 1)) + (1 << 23) * ($v >> 31 | 1);$exp = ($v >> 23 & 0xFF) - 127;return $x * pow(2, $exp - 23);}$a='42C88000 ';echo hexToDecFloat($a);
Equals 100.25
$s = '42C88000';echo current(unpack('f', pack('V', hexdec($s))));
100.25
$s = 'C1C90000';echo current(unpack('f', pack('V', hexdec($s))));
-25.125
Yes.
$s = 'C1C90000';echo current(unpack('f', pack('H*', join('', array_reverse(str_split($s, 2))))));
-25.125
# The code of 1 is only valid for positive numbers.
$a = 'C1C90000';echo hexToDecFloat($a);
-6.875
To be improved
Thank you for your help.