Return zero when division by zero instead of throwing exception
This commit is contained in:
@@ -128,8 +128,7 @@ class eqEOS {
|
|||||||
*/
|
*/
|
||||||
private function checkInfix($infix) {
|
private function checkInfix($infix) {
|
||||||
if(trim($infix) == "") {
|
if(trim($infix) == "") {
|
||||||
throw new Exception("No Equation given", EQEOS_E_NO_EQ);
|
return 0;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
//Make sure we have the same number of '(' as we do ')'
|
//Make sure we have the same number of '(' as we do ')'
|
||||||
// and the same # of '[' as we do ']'
|
// and the same # of '[' as we do ']'
|
||||||
@@ -301,8 +300,7 @@ class eqEOS {
|
|||||||
break;
|
break;
|
||||||
case '/':
|
case '/':
|
||||||
if($temp[$hold-1] == 0) {
|
if($temp[$hold-1] == 0) {
|
||||||
throw new Exception("Division by 0 on: '{$temp[$hold-2]} / {$temp[$hold-1]}' in {$this->inFix}", EQEOS_E_DIV_ZERO);
|
return 0;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
$temp[$hold-2] = $temp[$hold-2] / $temp[$hold-1];
|
$temp[$hold-2] = $temp[$hold-2] / $temp[$hold-1];
|
||||||
break;
|
break;
|
||||||
@@ -311,8 +309,7 @@ class eqEOS {
|
|||||||
break;
|
break;
|
||||||
case '%':
|
case '%':
|
||||||
if($temp[$hold-1] == 0) {
|
if($temp[$hold-1] == 0) {
|
||||||
throw new Exception("Division by 0 on: '{$temp[$hold-2]} % {$temp[$hold-1]}' in {$this->inFix}", EQEOS_E_DIV_ZERO);
|
return 0;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
$temp[$hold-2] = bcmod($temp[$hold-2], $temp[$hold-1]);
|
$temp[$hold-2] = bcmod($temp[$hold-2], $temp[$hold-1]);
|
||||||
break;
|
break;
|
||||||
@@ -398,24 +395,21 @@ class eqEOS {
|
|||||||
case "sec":
|
case "sec":
|
||||||
$tmp = cos($func);
|
$tmp = cos($func);
|
||||||
if($tmp == 0) {
|
if($tmp == 0) {
|
||||||
throw new Exception("Division by 0 on: 'sec({$func}) = 1/cos({$func})' in {$this->inFix}", EQEOS_E_DIV_ZERO);
|
return 0;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
$ans = 1/$tmp;
|
$ans = 1/$tmp;
|
||||||
break;
|
break;
|
||||||
case "csc":
|
case "csc":
|
||||||
$tmp = sin($func);
|
$tmp = sin($func);
|
||||||
if($tmp == 0) {
|
if($tmp == 0) {
|
||||||
throw new Exception("Division by 0 on: 'csc({$func}) = 1/sin({$func})' in {$this->inFix}", EQEOS_E_DIV_ZERO);
|
return 0;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
$ans = 1/$tmp;
|
$ans = 1/$tmp;
|
||||||
break;
|
break;
|
||||||
case "cot":
|
case "cot":
|
||||||
$tmp = tan($func);
|
$tmp = tan($func);
|
||||||
if($tmp == 0) {
|
if($tmp == 0) {
|
||||||
throw new Exception("Division by 0 on: 'cot({$func}) = 1/tan({$func})' in {$this->inFix}", EQEOS_E_DIV_ZERO);
|
return 0;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
$ans = 1/$tmp;
|
$ans = 1/$tmp;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user