note 106106 deleted from language.types.float by danbrown

From: Date: Sat, 02 Feb 2013 15:11:06 +0000
Subject: note 106106 deleted from language.types.float by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193498@lists.php.net to get a copy of this message
Note Submitter: cah4a at e-mail dot ua ---- Converting IEEE754 64 bit binary to float in 32bit php version: <?php function getDouble($bits) { if( strlen(binary_data)!=64 ) throw new Exception("wrong binary data"); $sign = $digits[0]; $exp = bindec(substr($bits, 1, 11)) - 1023; $mantissa_length = 30; // This is max workable length for 32bit representation of mantissa. We not use other (52-$mantissa_length bits) $man = (2 << ($mantissa_length-1)) + bindec(substr($bits, 12, $mantissa_length)); return $man * pow(2, $exp - $mantissa_length) * ($sign ? -1 : 1); } ?>

« previous php.notes (#193498) next »