<?php
class
BCCalculate
{
private
$leftNumber
;
private
$rightNumber
;
public
function
__construct(
$leftNumber
,
$rightNumber
)
{
$this
->leftNumber =
$leftNumber
;
$this
->rightNumber =
$rightNumber
;
$this
->setScale();
}
public
function
__set(
$name
,
$value
)
{
if
(!isset(
$this
->
$name
)) {
return
null;
}
$this
->
$name
=
$value
;
}
public
function
__get(
$name
)
{
if
(isset(
$this
->
$name
)) {
return
$this
->
$name
;
}
else
{
return
null;
}
}
public
function
__call(
$functionName
,
$arguments
)
{
if
(!method_exists(
$this
,
$functionName
)) {
return
null;
}
if
(isset(
$arguments
[0])) {
return
$this
->
$functionName
(
$arguments
[0]);
}
return
$this
->
$functionName
();
}
private
function
setScale(
$scale
= 2)
{
bcscale(
$scale
);
}
private
function
add()
{
return
bcadd
(
$this
->leftNumber,
$this
->rightNumber);
}
private
function
sub()
{
return
bcsub(
$this
->leftNumber,
$this
->rightNumber);
}
private
function
mul()
{
return
bcmul
(
$this
->leftNumber,
$this
->rightNumber);
}
private
function
p()
{
return
bcp(
$this
->leftNumber,
$this
->rightNumber);
}
private
function
comp()
{
return
bccomp
(
$this
->leftNumber,
$this
->rightNumber);
}
private
function
mod()
{
return
bcmod
(
$this
->leftNumber,
$this
->rightNumber);
}
private
function
pow()
{
return
bcpow(
$this
->leftNumber,
$this
->rightNumber);
}
private
function
sqrt()
{
return
bcsqrt(
$this
->leftNumber);
}
}
$bc
=
new
BCCalculate(3.45, 5.61);
var_dump(
$bc
->leftNumber);
echo
'<br />'
;
$bc
->leftNumber = 24.08;
var_dump(
$bc
->leftNumber);
echo
'<br />'
;
var_dump(
$bc
->add());
echo
'<br />'
;
$bc
->setScale(3);
var_dump(
$bc
->sub());
echo
'<br />'
;
var_dump(
$bc
->mul());
echo
'<br />'
;
var_dump(
$bc
->p());
echo
'<br />'
;
var_dump(
$bc
->comp());
echo
'<br />'
;
$bc
->leftNumber = 10;
$bc
->rightNumber = 4;
var_dump(
$bc
->mod());
echo
'<br />'
;
var_dump(
$bc
->pow());
echo
'<br />'
;
$bc
->leftNumber = 16;
var_dump(
$bc
->sqrt());
echo
'<br />'
;