aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Wells <brucekwells@gmail.com>2020-05-20 05:36:55 +0300
committerBruce Wells <brucekwells@gmail.com>2020-05-20 05:36:55 +0300
commitb95ab24f367baf928332dc5040ab444c1c719623 (patch)
tree20f7030e732f039263c9a2a4dfb5855d1b12cdeb /src
parentab3a44b33031d86c74cc8f07c9d904d8d20c7da9 (diff)
setDivisionByZeroIsZero
Diffstat (limited to 'src')
-rw-r--r--src/NXP/MathExecutor.php16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php
index 0b7e9db..e214209 100644
--- a/src/NXP/MathExecutor.php
+++ b/src/NXP/MathExecutor.php
@@ -468,6 +468,22 @@ class MathExecutor
return $this->tokenFactory->getFunctions();
}
+ /**
+ * Set division by zero returns zero instead of throwing DivisionByZeroException
+ *
+ * @return MathExecutor
+ */
+ public function setDivisionByZeroIsZero() : self
+ {
+ $this->addOperator(new Operator("/", false, 180, function ($a, $b) {
+ if ($b == 0) {
+ return 0;
+ }
+ return $a / $b;
+ }));
+ return $this;
+ }
+
public function __clone()
{
$this->addDefaults();