aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/brick/math/src/Exception
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/brick/math/src/Exception')
-rw-r--r--vendor/brick/math/src/Exception/DivisionByZeroException.php41
-rw-r--r--vendor/brick/math/src/Exception/IntegerOverflowException.php27
-rw-r--r--vendor/brick/math/src/Exception/MathException.php14
-rw-r--r--vendor/brick/math/src/Exception/NegativeNumberException.php12
-rw-r--r--vendor/brick/math/src/Exception/NumberFormatException.php35
-rw-r--r--vendor/brick/math/src/Exception/RoundingNecessaryException.php21
6 files changed, 150 insertions, 0 deletions
diff --git a/vendor/brick/math/src/Exception/DivisionByZeroException.php b/vendor/brick/math/src/Exception/DivisionByZeroException.php
new file mode 100644
index 000000000..a4e443176
--- /dev/null
+++ b/vendor/brick/math/src/Exception/DivisionByZeroException.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Brick\Math\Exception;
+
+/**
+ * Exception thrown when a division by zero occurs.
+ */
+class DivisionByZeroException extends MathException
+{
+ /**
+ * @return DivisionByZeroException
+ *
+ * @psalm-pure
+ */
+ public static function divisionByZero() : DivisionByZeroException
+ {
+ return new self('Division by zero.');
+ }
+
+ /**
+ * @return DivisionByZeroException
+ *
+ * @psalm-pure
+ */
+ public static function modulusMustNotBeZero() : DivisionByZeroException
+ {
+ return new self('The modulus must not be zero.');
+ }
+
+ /**
+ * @return DivisionByZeroException
+ *
+ * @psalm-pure
+ */
+ public static function denominatorMustNotBeZero() : DivisionByZeroException
+ {
+ return new self('The denominator of a rational number cannot be zero.');
+ }
+}
diff --git a/vendor/brick/math/src/Exception/IntegerOverflowException.php b/vendor/brick/math/src/Exception/IntegerOverflowException.php
new file mode 100644
index 000000000..e0b07d3c7
--- /dev/null
+++ b/vendor/brick/math/src/Exception/IntegerOverflowException.php
@@ -0,0 +1,27 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Brick\Math\Exception;
+
+use Brick\Math\BigInteger;
+
+/**
+ * Exception thrown when an integer overflow occurs.
+ */
+class IntegerOverflowException extends MathException
+{
+ /**
+ * @param BigInteger $value
+ *
+ * @return IntegerOverflowException
+ *
+ * @psalm-pure
+ */
+ public static function toIntOverflow(BigInteger $value) : IntegerOverflowException
+ {
+ $message = '%s is out of range %d to %d and cannot be represented as an integer.';
+
+ return new self(\sprintf($message, (string) $value, PHP_INT_MIN, PHP_INT_MAX));
+ }
+}
diff --git a/vendor/brick/math/src/Exception/MathException.php b/vendor/brick/math/src/Exception/MathException.php
new file mode 100644
index 000000000..21fda90e1
--- /dev/null
+++ b/vendor/brick/math/src/Exception/MathException.php
@@ -0,0 +1,14 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Brick\Math\Exception;
+
+/**
+ * Base class for all math exceptions.
+ *
+ * This class is abstract to ensure that only fine-grained exceptions are thrown throughout the code.
+ */
+class MathException extends \RuntimeException
+{
+}
diff --git a/vendor/brick/math/src/Exception/NegativeNumberException.php b/vendor/brick/math/src/Exception/NegativeNumberException.php
new file mode 100644
index 000000000..473911341
--- /dev/null
+++ b/vendor/brick/math/src/Exception/NegativeNumberException.php
@@ -0,0 +1,12 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Brick\Math\Exception;
+
+/**
+ * Exception thrown when attempting to perform an unsupported operation, such as a square root, on a negative number.
+ */
+class NegativeNumberException extends MathException
+{
+}
diff --git a/vendor/brick/math/src/Exception/NumberFormatException.php b/vendor/brick/math/src/Exception/NumberFormatException.php
new file mode 100644
index 000000000..2fd0be73a
--- /dev/null
+++ b/vendor/brick/math/src/Exception/NumberFormatException.php
@@ -0,0 +1,35 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Brick\Math\Exception;
+
+/**
+ * Exception thrown when attempting to create a number from a string with an invalid format.
+ */
+class NumberFormatException extends MathException
+{
+ /**
+ * @param string $char The failing character.
+ *
+ * @return NumberFormatException
+ *
+ * @psalm-pure
+ */
+ public static function charNotInAlphabet(string $char) : self
+ {
+ $ord = \ord($char);
+
+ if ($ord < 32 || $ord > 126) {
+ $char = \strtoupper(\dechex($ord));
+
+ if ($ord < 10) {
+ $char = '0' . $char;
+ }
+ } else {
+ $char = '"' . $char . '"';
+ }
+
+ return new self(sprintf('Char %s is not a valid character in the given alphabet.', $char));
+ }
+}
diff --git a/vendor/brick/math/src/Exception/RoundingNecessaryException.php b/vendor/brick/math/src/Exception/RoundingNecessaryException.php
new file mode 100644
index 000000000..1c6100563
--- /dev/null
+++ b/vendor/brick/math/src/Exception/RoundingNecessaryException.php
@@ -0,0 +1,21 @@
+<?php
+
+declare(strict_types=1);
+
+namespace Brick\Math\Exception;
+
+/**
+ * Exception thrown when a number cannot be represented at the requested scale without rounding.
+ */
+class RoundingNecessaryException extends MathException
+{
+ /**
+ * @return RoundingNecessaryException
+ *
+ * @psalm-pure
+ */
+ public static function roundingNecessary() : RoundingNecessaryException
+ {
+ return new self('Rounding is necessary to represent the result of the operation at this scale.');
+ }
+}