Page 1 of 1

Multiply decimal numbers with "gmp_mul"

Posted: Sat Apr 17, 2010 8:26 am
by Nexon
Hello,

Today I tried to code a bit of my school maths in PHP. Because of the fact, that I need in parts really big numbers, I use the gmplib extension and its functions. One of this functions, "gmp_mul", multiplys two numbers by each other. In general, this works fine, but if one or two of this numbers is a decimal number, the result is always zero. Example:

Code: Select all

<?php
echo '0.5*0.5 = ".gmp_strval(gmp_mul('0.5','0.5'));
?>
results in
0.5*0.5 = 0
and I don't get any error of my local webserver (lighttpd).

What am I doing wrong? The description of "gmp_mul"says "Multiplies a by b and returns the result."

An overwiew of the GMP PHP functions can be found here: http://www.php.net/manual/en/ref.gmp.php

Thanks in advance for any help and please excuse my bad English, I hope I described the problem in an understandable way.

Greetings
Nexon

Re: Multiply decimal numbers with "gmp_mul"

Posted: Sat Apr 17, 2010 9:53 am
by JAY6390
Hi Nexon

The GMP library seems to only support integers as far as I can tell. I would suggest you take a look at the BCM library (bcmul in this case)