programming-examples/php/Math/PHP script to extract mantissa and exponent from a floating point value..php

8 lines
281 B
PHP
Raw Permalink Normal View History

2019-11-15 12:59:38 +01:00
<?php
$float_num = 0.0456;
$exponent_part = ( floor(log($float_num, 2)) + 1 );
$mantissa_part = ( $float_num * pow(2, -$exponent_part) );
echo 'Floating value : '.$float_num."\n";
echo 'Exponent part : '.$exponent_part."\n";
echo 'Mantissa part : '.$mantissa_part."\n";
?>