Сложный путь:
$signmap = Array(
-1 => '-',
1 => ''
);
function fractur($f)
{
if ($f < 0)
{
$sign = -1;
$f = -$f;
} else {
$sign = 1;
};
$intp = floor($f);
$fracp = $f - $intp;
return Array($sign, $intp, $fracp);
};
function float2var($f, $spec)
{
global $signmap;
list($sign, $intp, $fracp) = fractur($f);
$format = sprintf('%%s%s.%s', $spec, $spec);
$ret = sprintf($format, $signmap[$sign], $intp, $fracp * 16777216);
// 64-bit systems can use the next line instead
//$ret = sprintf($format, $signmap[$sign], $intp, $fracp * 18014398509481984);
return rtrim(rtrim($ret, '0'), '.');
};
function float2bin($f)
{
return float2var($f, '%b');
};
function float2oct($f)
{
return float2var($f, '%o');
};
function float2hex($f)
{
return float2var($f, '%x');
};
var_dump(float2bin(10.5));
var_dump(float2bin(10));
var_dump(float2bin(-2.5));
var_dump(float2bin(2.5));
var_dump(float2oct(2.5));
var_dump(float2hex(2.5));