|
static | validateComplexArgument ($complex) |
| Validates whether the argument is a valid complex number, converting scalar or array values if possible. More...
|
|
|
const | EULER = 2.7182818284590452353602874713526624977572 |
| Euler's Number. More...
|
|
const | NUMBER_SPLIT_REGEXP |
| Regexp to split an input string into real and imaginary components and suffix More...
|
|
|
static | parseComplex ($complexNumber) |
| Validates whether the argument is a valid complex number, converting scalar or array values if possible. More...
|
|
Definition at line 60 of file Complex.php.
◆ __construct()
Complex\Complex::__construct |
( |
|
$realPart = 0.0 , |
|
|
|
$imaginaryPart = null , |
|
|
|
$suffix = 'i' |
|
) |
| |
◆ __call()
Complex\Complex::__call |
( |
|
$functionName, |
|
|
|
$arguments |
|
) |
| |
Returns the result of the function call or operation.
- Returns
- Complex|float
- Exceptions
-
Definition at line 374 of file Complex.php.
376 $functionName = strtolower(str_replace(
'_',
'', $functionName));
379 if (in_array($functionName, self::$functions,
true)) {
380 $functionName =
"\\" . __NAMESPACE__ .
"\\{$functionName}";
381 return $functionName($this, ...$arguments);
384 if (in_array($functionName, self::$operations,
true)) {
385 $functionName =
"\\" . __NAMESPACE__ .
"\\{$functionName}";
386 return $functionName($this, ...$arguments);
388 throw new Exception(
'Complex Function or Operation does not exist');
◆ __toString()
Complex\Complex::__toString |
( |
| ) |
|
◆ format()
Complex\Complex::format |
( |
| ) |
|
Definition at line 242 of file Complex.php.
245 if ($this->imaginaryPart != 0.0) {
246 if (\abs($this->imaginaryPart) != 1.0) {
249 $str .= (($this->imaginaryPart < 0.0) ?
'-' :
'') . $this->suffix;
252 if ($this->realPart != 0.0) {
253 if (($str) && ($this->imaginaryPart > 0.0)) {
256 $str = $this->realPart . $str;
◆ getImaginary()
Complex\Complex::getImaginary |
( |
| ) |
|
Gets the imaginary part of this complex number.
- Returns
- Float
Definition at line 207 of file Complex.php.
◆ getReal()
Complex\Complex::getReal |
( |
| ) |
|
Gets the real part of this complex number.
- Returns
- Float
Definition at line 197 of file Complex.php.
◆ getSuffix()
Complex\Complex::getSuffix |
( |
| ) |
|
Gets the suffix of this complex number.
- Returns
- String
Definition at line 217 of file Complex.php.
◆ invertImaginary()
Complex\Complex::invertImaginary |
( |
| ) |
|
Definition at line 302 of file Complex.php.
306 $this->imaginaryPart * -1,
307 ($this->imaginaryPart == 0.0) ? null : $this->suffix
◆ invertReal()
Complex\Complex::invertReal |
( |
| ) |
|
Definition at line 311 of file Complex.php.
314 $this->realPart * -1,
315 $this->imaginaryPart,
316 ($this->imaginaryPart == 0.0) ? null : $this->suffix
◆ isComplex()
Complex\Complex::isComplex |
( |
| ) |
|
Returns true if this is a complex value, false if a real value.
- Returns
- Bool
Definition at line 237 of file Complex.php.
isReal()
Returns true if this is a real value, false if a complex value.
◆ isReal()
Complex\Complex::isReal |
( |
| ) |
|
Returns true if this is a real value, false if a complex value.
- Returns
- Bool
Definition at line 227 of file Complex.php.
229 return $this->imaginaryPart == 0.0;
◆ parseComplex()
static Complex\Complex::parseComplex |
( |
|
$complexNumber | ) |
|
|
staticprivate |
Validates whether the argument is a valid complex number, converting scalar or array values if possible.
- Parameters
-
mixed | $complexNumber | The value to parse |
- Returns
- array
- Exceptions
-
Definition at line 109 of file Complex.php.
112 if (is_numeric($complexNumber)) {
113 return [$complexNumber, 0, null];
117 $complexNumber = str_replace(
118 [
'+-',
'-+',
'++',
'--'],
119 [
'-',
'-',
'+',
'+'],
124 $validComplex = preg_match(
125 self::NUMBER_SPLIT_REGEXP,
130 if (!$validComplex) {
132 $validComplex = preg_match(
'/^([\-\+]?)([ij])$/ui', $complexNumber, $complexParts);
133 if (!$validComplex) {
134 throw new Exception(
'Invalid complex number');
138 if ($complexParts[1] ===
'-') {
139 $imaginary = 0 - $imaginary;
141 return [0, $imaginary, $complexParts[2]];
145 if (($complexParts[4] ===
'') && ($complexParts[9] !==
'')) {
146 if ($complexParts[7] !== $complexParts[9]) {
147 $complexParts[4] = 1;
148 if ($complexParts[8] ===
'-') {
149 $complexParts[4] = -1;
154 $complexParts[4] = $complexParts[1];
155 $complexParts[1] = 0;
163 !empty($complexParts[9]) ? $complexParts[9] :
'i'
◆ reverse()
Complex\Complex::reverse |
( |
| ) |
|
Returns the reverse of this complex number.
- Returns
- Complex
Definition at line 293 of file Complex.php.
296 $this->imaginaryPart,
298 ($this->realPart == 0.0) ? null : $this->suffix
◆ validateComplexArgument()
static Complex\Complex::validateComplexArgument |
( |
|
$complex | ) |
|
|
static |
Validates whether the argument is a valid complex number, converting scalar or array values if possible.
- Parameters
-
mixed | $complex | The value to validate |
- Returns
- Complex
- Exceptions
-
Definition at line 277 of file Complex.php.
279 if (is_scalar($complex) || is_array($complex)) {
280 $complex =
new Complex($complex);
281 } elseif (!is_object($complex) || !($complex instanceof
Complex)) {
282 throw new Exception(
'Value is not a valid complex number');
◆ $functions
Complex\Complex::$functions |
|
staticprotected |
◆ $imaginaryPart
Complex\Complex::$imaginaryPart = 0.0 |
|
protected |
◆ $operations
Complex\Complex::$operations |
|
staticprotected |
Initial value:= [
'add',
'subtract',
'multiply',
'divideby',
'divideinto',
]
Definition at line 360 of file Complex.php.
◆ $realPart
Complex\Complex::$realPart = 0.0 |
|
protected |
◆ $suffix
◆ EULER
const Complex\Complex::EULER = 2.7182818284590452353602874713526624977572 |
◆ NUMBER_SPLIT_REGEXP
const Complex\Complex::NUMBER_SPLIT_REGEXP |
Initial value:=
'` ^
( # Real part
[-+]?(\d+\.?\d*|\d*\.?\d+) # Real value (integer or float)
([Ee][-+]?[0-2]?\d{1,3})? # Optional real exponent for scientific format
)
( # Imaginary part
[-+]?(\d+\.?\d*|\d*\.?\d+) # Imaginary value (integer or float)
([Ee][-+]?[0-2]?\d{1,3})? # Optional imaginary exponent for scientific format
)?
( # Imaginary part is optional
([-+]?) # Imaginary (implicit 1 or -1) only
([ij]?) # Imaginary i or j - depending on whether mathematical or engineering
)
$`uix'
Regexp to split an input string into real and imaginary components and suffix
Definition at line 70 of file Complex.php.
The documentation for this class was generated from the following file:
- libs/composer/vendor/markbaker/complex/classes/src/Complex.php