note 97549 added to function.pow

From: Date: Sun, 25 Apr 2010 21:24:10 +0000
Subject: note 97549 added to function.pow
Groups: php.notes 
Request: Send a blank email to php-notes+get-168629@lists.php.net to get a copy of this message
You can increase the 'precision' php.ini setting a little to work with larger float numbers here, but this comes at at cost of sacrificing decimal accuracy. The default 'precision' is 14. 5 is about the threshhold that php can handle for decimal accuracy before at least some number corruption starts showing or it cannot output the actual number, and 22 for large number accuracy. See the table below for an example, and adjust your php.ini 'precision' setting according to what your OS and PHP version can handle and what number size you want to work with. Alternatively, you can use the bc math functions for more accuracy all around, and not have to rely on the 'precision' ini setting at all, but this moves out of the realm of strictly floats and into strings. <?php echo "<table>"; for($i = 0; $i < 50; $i++) { $precision = $i + 1; ini_set('precision', $precision); echo "<tr>"; echo "<td>".$precision."</td>"; echo "<td>".pow(10, $i)."</td>"; echo "<td>".pow(10, (-1 * $i))."</td>"; echo "<td>".bcpow('10', (string) $i, $precision)."</td>"; echo "<td>".bcpow('10', (string) (-1 * $i), $precision)."</td>"; echo "</tr>"; } echo "</table>"; ?> ---- Server IP: 192.41.40.227 Probable Submitter: 66.25.188.193 ---- Manual Page -- http://www.php.net/manual/en/function.pow.php Edit -- https://master.php.net/note/edit/97549 Del: integrated -- https://master.php.net/note/delete/97549/integrated Del: useless -- https://master.php.net/note/delete/97549/useless Del: bad code -- https://master.php.net/note/delete/97549/bad+code Del: spam -- https://master.php.net/note/delete/97549/spam Del: non-english -- https://master.php.net/note/delete/97549/non-english Del: in docs -- https://master.php.net/note/delete/97549/in+docs Del: other reasons-- https://master.php.net/note/delete/97549 Reject -- https://master.php.net/note/reject/97549 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168629) next »