note 108606 deleted from function.bcpow by salathe
| From: | salathe@php.net | Date: | Thu, 10 May 2012 08:16:50 +0000 |
| Subject: | note 108606 deleted from function.bcpow by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187567@lists.php.net to get a copy of this message | ||
Note Submitter: github.com/alixaxel/phunction/
----
If anyone else is also going nuts with the second argument being casted to an integer -- see https://bugs.php.net/bug.php?id=10116 -- (and thus
being unable to calculate roots using bcpow), I wrote a convenient wrapper around BCMath functions
that solves this problem (while respecting PEMDAS):
<?php
var_dump(BC('4.0 ^ 0.5')); // 2
var_dump(BC('4.0 ^ 2.5')); // 32
var_dump(BC('4.8 ^ 2.5')); // 2.1908902300207...
var_dump(BC('4.0 ^ 1 / 3')); // 1.3333333333333...
var_dump(BC('4.0 ^ (1 / 3)')); // 1.5874010519682...
var_dump(BC('4.0 ^ 2.5 >= 4.0 ^ 0.5')); // 1
?>
The source is a bit long to post here, but you can get it at https://github.com/alixaxel/phunction/blob/c9e276713d3981a08043a95cc94cf96f264e39d4/phunction/Math.php#L74.