bcmath

How to install bcmath module?

谁都会走 提交于 2019-11-28 10:39:32
How do I install the bcmath module on a server? I tried yum update php-bcmath but it said it found nothing. Try yum install php-bcmath . If you still can't find anything, try yum search bcmath to find the package name ubuntu and php7.1 sudo apt install php7.1-bcmath Worked great on CentOS 6.5 yum install bcmath All my calls to bcmath functions started working right after an apache restart service httpd restart Sweet! yum install php72-php-bcmath.x86_64 cp /etc/opt/remi/php72/php.d/20-bcmath.ini /etc/php.d/ cp /opt/remi/php72/root/usr/lib64/php/modules/bcmath.so /usr/lib64/php/modules/

Calculating roots with bc_math or GMP

心不动则不痛 提交于 2019-11-28 04:55:58
问题 I'm having trouble calculating roots of rather large numbers using bc_math, example: - pow(2, 2) // 4, power correct - pow(4, 0.5) // 2, square root correct - bcpow(2, 2) // 4, power correct - bcpow(4, 0.5) // 1, square root INCORRECT Does anybody knows how I can circumvent this? gmp_pow() also doesn't work. 回答1: I'm not a PHP programmer but looking at the manual it says you have to pass them in as strings i.e. bcpow( '4', '0.5' ) Does that help? Edit : The user contributed notes in the

In PHP, how do I generate a big pseudo-random number?

▼魔方 西西 提交于 2019-11-27 14:23:13
I'm looking for a way to generate a big random number with PHP, something like: mt_rand($lower, $upper); The closer I've seen is gmp_random () however it doesn't allow me to specify the lower and upper boundaries only the number of bits per limb (which I've no idea what it is). EDIT: Axsuuls answer seems to be pretty close to what I want and very similar to gmp_random however there seems to be only one flaw in one scenario. Suppose I wan't to get a random number between: 1225468798745475454898787465154 and: 1225468798745475454898787465200 So if the function is called BigRandomNumber ():

How to install bcmath module?

▼魔方 西西 提交于 2019-11-27 05:53:32
问题 How do I install the bcmath module on a server? I tried yum update php-bcmath but it said it found nothing. 回答1: Try yum install php-bcmath . If you still can't find anything, try yum search bcmath to find the package name 回答2: ubuntu and php7.1 sudo apt install php7.1-bcmath ubuntu and php without version specification sudo apt install php-bcmath 回答3: Worked great on CentOS 6.5 yum install bcmath All my calls to bcmath functions started working right after an apache restart service httpd

In PHP, how do I generate a big pseudo-random number?

蹲街弑〆低调 提交于 2019-11-26 18:24:03
问题 I'm looking for a way to generate a big random number with PHP, something like: mt_rand($lower, $upper); The closer I've seen is gmp_random() however it doesn't allow me to specify the lower and upper boundaries only the number of bits per limb (which I've no idea what it is). EDIT: Axsuuls answer seems to be pretty close to what I want and very similar to gmp_random however there seems to be only one flaw in one scenario. Suppose I wan't to get a random number between:

Raising to power in PHP

心不动则不痛 提交于 2019-11-26 17:21:19
问题 Well, i need to do some calculations in PHP script. And i have one expression that behaves wrong. echo 10^(-.01); Outputs 10 echo 1 / (10^(.01)); Outputs 0 echo bcpow('10', '-0.01') . '<br/>'; Outputs 1 echo bcdiv('1', bcpow('10', '0.01')); Outputs 1.000.... I'm using bcscale(100) for BCMath calculations. Excel and Wolfram Mathematica give answer ~0,977237. Any suggestions? 回答1: The caret is the bit-wise XOR operator in PHP. You need to use pow() for integers. 回答2: PHP 5.6 finally introduced

How to ceil, floor and round bcmath numbers?

六眼飞鱼酱① 提交于 2019-11-26 16:41:46
问题 I need to mimic the exact functionality of the ceil(), floor() and round() functions on bcmath numbers , I've already found a very similar question but unfortunately the answer provided isn't good enough for me since it lacks support for negative numbers and the precision argument for the round() function is missing . I was wondering if anyone can come up with a rather short and elegant solution to this problem. All input is appreciated, thanks! 回答1: After a night lost trying to solve this