Questions tagged [bcmath]

BC Math is a binary calculator for PHP which supports numbers of any size and precision, represented as strings.

BC Math is a binary calculator for PHP which supports numbers of any size and precision, represented as strings.

BC Math Functions

  • bcadd() ~ Add two arbitrary precision numbers
  • bccomp() ~ Compare two arbitrary precision numbers
  • bcdiv() ~ Divide two arbitrary precision numbers
  • bcmod() ~ Get modulus of an arbitrary precision number
  • bcmul() ~ Multiply two arbitrary precision number
  • bcpow() ~ Raise an arbitrary precision number to another
  • bcpowmod() ~ Raise an arbitrary precision number to another, reduced by a specified modulus
  • bcscale() ~ Set default scale parameter for all bc math functions
  • bcsqrt() ~ Get the square root of an arbitrary precision number
  • bcsub() ~ Subtract one arbitrary precision number from another
100 questions
1
vote
0 answers

Is there any particular reason that PHP doesn't do bcadd() whenever + is used?

Whenever I'm dealing with numbers in PHP which represent money, I'm forced to use bcadd() and the other functions in that "family", instead of simply using the nice symbols such as +, -, / and *. The reason is something about "floats" being…
1
vote
2 answers

How to multiply small floats with unkown number of decimal places in PHP withouth getting zero because of scientific notation?

I'm trying to multiply some small numbers in PHP, but bcmul is returning zero because the float value is being turned into scientific notation. I tried using sprintf('%.32f',$value) on the small float values, but since the number of decimal places…
Miguel Vieira
  • 144
  • 3
  • 17
1
vote
0 answers

Undefined function bandwidthThrottle\tokenBucket\util\bcsub() When bcsub installed on all php versions on the server

I've got a project on an Ubutu server. I keep getting the following error \FatalThrowableError: Call to undefined function bandwidthThrottle\tokenBucket\util\bcsub() in vendor/bandwidth-throttle/token-bucket/classes/util/TokenConverter.php:80 …
GingerFish
  • 457
  • 3
  • 11
  • 26
1
vote
3 answers

Trying to decrypt a PHP PseudoCrypt class

I am trying to create a way to reverse the PseudoCrypt script listed at: http://blog.kevburnsjr.com/php-unique-hash. In this code it has the following equation: $dec = ($num * $prime)-floor($num * $prime/$ceil)*$ceil; I have been able to get every…
DanielJay
  • 292
  • 3
  • 13
1
vote
1 answer

why does bccomp require a scale to work properly?

php > var_dump(bccomp('-10.00001', '-10.0')); int(0) php > var_dump(bccomp('-10.00001', '-10.0', 17)); int(-1); I don't get this at all. Isn't the entire point of the bcmath functions to allow you to do comparisons/arithmatic on floating point…
user10846907
1
vote
0 answers

I installed bcmath, but I can't get my laravel project find it

I am working on a Laravel project using the auth scaffolding. When trying the link "forgot your password" with a valid mail address, I get the following error: The BCMath functions must be enabled to use the NTLM authenticator. Following other…
rocambille
  • 15,398
  • 12
  • 50
  • 68
1
vote
4 answers

bcmath seems to give the wrong answer to my calculation

I am not sure what I am doing wrong but this calculation bcscale(20); echo bcmul(bcdiv('422218', '2388865'), '473'); echoes "83.59999999999999999670" but every other calculator gives me 83.6. Is there a way to solve this or is it a flaw in bcmath?
Zzzarka
  • 13
  • 3
1
vote
2 answers

how to add bcmath extension in php 5.6 with php-fpm on Centos 7

I am trying to add bcmath extension on my Centos 7 which has PHP 5.6 installed along with nginx and php-fpm I ran yum install php56-bcmath Above installed the bcmath extension which I can see under the 'module' column in phpinfo() output. However…
Sahil
  • 1,959
  • 6
  • 24
  • 44
1
vote
1 answer

bcmath operations with very small numbers

I want to use bcmath for precise operations with very small numbers, but it fails. I am trying to calculate cryptocurrency prices and thought that bcmath is better than converting float to integers This working: php > echo number_format(0.000005 *…
1
vote
1 answer

How install Intl, GMP and BCMath PHP extensions?

Centos 6.8 Final Php 7.0.16 Directadmin control panel yum install php-gmp yum install php-bcmath yum install php-intl result is: No package xxx available. Thank you.
M ak
  • 21
  • 1
  • 6
1
vote
2 answers

Two files, exactly the same code, different output?

This is the weirdest thing that has ever happened to me since I am a (PHP) programmer... I have two files, with the following code (proj. euler stuff) that return different outputs.
acm
  • 6,541
  • 3
  • 39
  • 44
1
vote
1 answer

translate a few >32-bit operations to work in a php 32-bit environment

My webhost reports that PHP_INT_MAX is 2147483647, i.e. it's a 32-bit environment. I'm trying to convert a couple of mathematical operations that currently works in a 64-bit environment, so that they also work in the 32-bit environment. $id =…
Linus Proxy
  • 525
  • 1
  • 5
  • 21
1
vote
1 answer

How much precision for a bcmath PHP library?

I'm writing a PHP library that has a Number class that uses the bcmath extension for arbitrary precision. I have two questions: How much slower is bcmath compared to using the built-in int and float types? bcmath has an optional scale argument…
cdmckay
  • 31,832
  • 25
  • 83
  • 114
1
vote
0 answers

How to add a library to PHP?

My version of PHP, 5.3.8, doesn't contain BC-Math, which is needed for many cryptocurrency functions. Google hasn't been particularly helpful for links on how to install this particularly library, so I'm at a total loss on how to add it to my…
tim peterson
  • 23,653
  • 59
  • 177
  • 299
1
vote
5 answers

PHP bcdiv() division by zero on large numbers

The following code gives "Warning: bcdiv() [function.bcdiv]: Division by zero in ..." $a = 20000000000000002; $b = 20000000000000004; echo bcdiv($a, $b); Why does this happen? If I put the values in "" then it doesn't give a warning.
user2091163