幂大浮点数 (100.33^360)

Power big float numbers (100.33^360)

我有问题:

pow(100.33, 360); // return INF

我使用 GMP,但这没有得到浮点数:

gmp_strval(gmp_pow('2', 3)); //return 8
gmp_strval(gmp_pow('2.0', 3)); //return 0

请帮忙 :) 怎么做?

来自PHP GMP documentation page

These functions allow you to work with arbitrary-length INTEGERS using the GNU MP library.

换句话说,不允许浮点数。 GMP 本身可以进行浮点运算,但它的 PHP 接口似乎没有发挥其全部功能。

您可以使用 bcpow 来获得此功能,例如:

$num = bcpow('100.33', '360', 20);
echo $num;

这输出:

3274103534834396431867559103093187830103180578316133866868
8735096209772372540787863291005903612118038812972585250990
9184783128175191070195558359762317865469719418788175465726
2260403727769361000933644502616255136475528818978181028888
7900899387124705985519483201689097535257257471686279645479
0293787644875616262913286836073610372960697383687245477891
3127091993585718764278131719726387787145646698001143323773
8827166195539744295014989026208988133960971242873367417385
5744373185506374857530249495974084141129611541831378797038
9257147348718093640732700784857982966810730374711336160716
5240002574688357771367833219551029582525497843733924244263
5089812833806492039068418216603999851813542524325083024650
6447037300606418104334363.93719644178064144117

@paxdiablo 是对的。 gmp_pow 不允许浮点值。你会收到警告

Warning: gmp_pow(): Unable to convert variable to GMP - wrong type in Command line code

您可以使用 bcpow 来实现 http://php.net/manual/en/function.bcpow.php