GMP and floating point numbers?

The following code outputs 0, which is incorrect:

$r = gmp_pow(gmp_init('-1.7976931348623157'), 308); echo gmp_strval($r); 

Did I get the impression that the GMP library is capable of handling floating point numbers or did I make a mistake in the code?

+7
source share
1 answer

GMP library is capable of handling floating point numbers,

This is not true. You can check this with:

 echo gmp_strval(gmp_init('18')); // 18 echo gmp_strval(gmp_init('1.8')); // 0 

Now you can use BCMath :

 $num = bcpow('-1.7976931348623157', '308'); echo $num; echo floatval($num); // for a "prettier" format 
+10
source

All Articles