本文整理匯總了PHP中getid3_lib::DecimalBinary2Float方法的典型用法代碼示例。如果您正苦於以下問題:PHP getid3_lib::DecimalBinary2Float方法的具體用法?PHP getid3_lib::DecimalBinary2Float怎麽用?PHP getid3_lib::DecimalBinary2Float使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類getid3_lib
的用法示例。
在下文中一共展示了getid3_lib::DecimalBinary2Float方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: BigEndian2Float
static function BigEndian2Float($byteword)
{
// ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
// http://www.psc.edu/general/software/packages/ieee/ieee.html
// http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
$bitword = getid3_lib::BigEndian2Bin($byteword);
if (!$bitword) {
return 0;
}
$signbit = $bitword[0];
switch (strlen($byteword) * 8) {
case 32:
$exponentbits = 8;
$fractionbits = 23;
break;
case 64:
$exponentbits = 11;
$fractionbits = 52;
break;
case 80:
// 80-bit Apple SANE format
// http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
$exponentstring = substr($bitword, 1, 15);
$isnormalized = intval($bitword[16]);
$fractionstring = substr($bitword, 17, 63);
$exponent = pow(2, getid3_lib::Bin2Dec($exponentstring) - 16383);
$fraction = $isnormalized + getid3_lib::DecimalBinary2Float($fractionstring);
$floatvalue = $exponent * $fraction;
if ($signbit == '1') {
$floatvalue *= -1;
}
return $floatvalue;
break;
default:
return false;
break;
}
$exponentstring = substr($bitword, 1, $exponentbits);
$fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
$exponent = getid3_lib::Bin2Dec($exponentstring);
$fraction = getid3_lib::Bin2Dec($fractionstring);
if ($exponent == pow(2, $exponentbits) - 1 && $fraction != 0) {
// Not a Number
$floatvalue = false;
} elseif ($exponent == pow(2, $exponentbits) - 1 && $fraction == 0) {
if ($signbit == '1') {
$floatvalue = '-infinity';
} else {
$floatvalue = '+infinity';
}
} elseif ($exponent == 0 && $fraction == 0) {
if ($signbit == '1') {
$floatvalue = -0;
} else {
$floatvalue = 0;
}
$floatvalue = $signbit ? 0 : -0;
} elseif ($exponent == 0 && $fraction != 0) {
// These are 'unnormalized' values
$floatvalue = pow(2, -1 * (pow(2, $exponentbits - 1) - 2)) * getid3_lib::DecimalBinary2Float($fractionstring);
if ($signbit == '1') {
$floatvalue *= -1;
}
} elseif ($exponent != 0) {
$floatvalue = pow(2, $exponent - (pow(2, $exponentbits - 1) - 1)) * (1 + getid3_lib::DecimalBinary2Float($fractionstring));
if ($signbit == '1') {
$floatvalue *= -1;
}
}
return (double) $floatvalue;
}