Settings | Sign in | Sign up

There are currently 25 posts.

使用php的bcmath庫,可以瞬間算出2的2010次方

Floor 22 巨大八爪鱼 2/24/15 10:14
$num = 8;
$pow = 1/3;
echo pow($num, $pow);
這個可以算8的立方根,但是不能用在bcpow函數中。。。
Floor 23 巨大八爪鱼 2/24/15 10:17
bcmath庫目前的缺陷就是:無法算任意數的n次方根
Floor 24 巨大八爪鱼 2/24/15 10:40
<?php
$two = gmp_init(27);
$cuberoot = gmp_root($two, 3); //開三次方
echo gmp_strval($cuberoot); //十進制
echo "<br>";
echo gmp_strval($cuberoot, 2); //二進制
?>
還可以用gmp庫算三次根
在該例子中只能算出整數結果,比如算三次根號9得出的結果還是2.。。。
Floor 25 巨大八爪鱼 2/24/15 10:43
Be careful with GMP - it considers leading zeros in a number string as meaning the number is in octal, whereas 'bc' doesn't:

  gmp_strval("000100", 10) => 64

  bcmul("000100", "1") => 100

gmp會把0開頭的數視爲八進制數,而bcmath不會
Floor 26 巨大八爪鱼 2/25/15 16:48

回復:4樓

100,000^2 = (10^5)^2=10^10=10,000,000,000

可見,2的十萬次方比十萬的平方大多了

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.