BC Math (Binary Calculator)

Download php eBook

Introduction

The Binary Calculator can be used to calculate with numbers of any size and precision up to 2147483647-1 decimals, in string format. The Binary Calculator is more precise than the float calculation of PHP.

Syntax

  • string bcadd ( string $left_operand , string $right_operand [, int $scale = 0 ] )
  • int bccomp ( string $left_operand , string $right_operand [, int $scale = 0 ] )
  • string bcdiv ( string $left_operand , string $right_operand [, int $scale = 0 ] )
  • string bcmod ( string $left_operand , string $modulus )
  • string bcmul ( string $left_operand , string $right_operand [, int $scale = 0 ] )
  • string bcpowmod ( string $left_operand , string $right_operand , string $modulus [, int $scale = 0 ] )
  • bool bcscale ( int $scale )
  • string bcsqrt ( string $operand [, int $scale = 0 ] )
  • string bcsub ( string $left_operand , string $right_operand [, int $scale = 0 ] )

Parameters

bcaddAdd two arbitrary precision numbers.
left_operandThe left operand, as a string.
right_operandThe right operand, as a string.
scaleA optional parameter to set the number of digits after the decimal place in the result.
bccompCompare two arbitrary precision numbers.
left_operandThe left operand, as a string.
right_operandThe right operand, as a string.
scaleA optional parameter to set the number of digits after the decimal place which will be used in the comparison.
bcdivDivide two arbitrary precision numbers.
left_operandThe left operand, as a string.
right_operandThe right operand, as a string.
scaleA optional parameter to set the number of digits after the decimal place in the result.
bcmodGet modulus of an arbitrary precision number.
left_operandThe left operand, as a string.
modulusThe modulus, as a string.
bcmulMultiply two arbitrary precision numbers.
left_operandThe left operand, as a string.
right_operandThe right operand, as a string.
scaleA optional parameter to set the number of digits after the decimal place in the result.
bcpowRaise an arbitrary precision number to another.
left_operandThe left operand, as a string.
right_operandThe right operand, as a string.
scaleA optional parameter to set the number of digits after the decimal place in the result.
bcpowmodRaise an arbitrary precision number to another, reduced by a specified modulus.
left_operandThe left operand, as a string.
right_operandThe right operand, as a string.
modulusThe modulus, as a string.
scaleA optional parameter to set the number of digits after the decimal place in the result.
bcscaleSet default scale parameter for all bc math functions.
scaleThe scale factor.
bcsqrtGet the square root of an arbitrary precision number.
operandThe operand, as a string.
scaleA optional parameter to set the number of digits after the decimal place in the result.
bcsubSubtract one arbitrary precision number from another.
left_operandThe left operand, as a string.
right_operandThe right operand, as a string.
scaleA optional parameter to set the number of digits after the decimal place in the result.

Remarks

For all BC functions, if the scale parameter is not set, it defaults to 0, which will make all operations integer operations.

Related Examples

Stats

80 Contributors: 2
Wednesday, January 4, 2017
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook