PHPackages                             mykola-ivashchuk-gl/complex - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mykola-ivashchuk-gl/complex

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mykola-ivashchuk-gl/complex
===========================

PHP Class for working with complex numbers supporting PHP 5.5.9

2.0.0(5y ago)011MITPHPPHP ^7.2 || ^8.0

Since Mar 18Pushed 5y agoCompare

[ Source](https://github.com/mykola-ivashchuk-gl/PHPComplex)[ Packagist](https://packagist.org/packages/mykola-ivashchuk-gl/complex)[ Docs](https://github.com/MarkBaker/PHPComplex)[ RSS](/packages/mykola-ivashchuk-gl-complex/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (1)Dependencies (8)Versions (23)Used By (0)

PHPComplex
==========

[](#phpcomplex)

---

What was changed?
-----------------

[](#what-was-changed)

Added support for PHP 5.5.9

---

PHP Class for handling Complex numbers

Master: [![Build Status](https://camo.githubusercontent.com/e163b507cd40566f3874f392e7a9cbe9cf8ab3de57b660dd599647b09014dc51/68747470733a2f2f7472617669732d63692e6f72672f4d61726b42616b65722f504850436f6d706c65782e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/MarkBaker/PHPComplex)

Develop: [![Build Status](https://camo.githubusercontent.com/3c13acf6992964bd35855345bae1b93874c9e93c86fbfa34d3c4fb99f45bb2a7/68747470733a2f2f7472617669732d63692e6f72672f4d61726b42616b65722f504850436f6d706c65782e706e673f6272616e63683d646576656c6f70)](http://travis-ci.org/MarkBaker/PHPComplex)

[![Complex Numbers](https://camo.githubusercontent.com/2bbee9afe0d3ef53e31f62819febb5c3fdce2aef5d8cfa4a0c1b038ec2ab38fc/68747470733a2f2f696d67732e786b63642e636f6d2f636f6d6963732f636f6d706c65785f6e756d626572735f32782e706e67)](https://xkcd.com/2028/)

---

The library currently provides the following operations:

- addition
- subtraction
- multiplication
- division
    - division by
    - division into

together with functions for

- theta (polar theta angle)
- rho (polar distance/radius)
- conjugate

- negative

- inverse (1 / complex)
- cos (cosine)
- acos (inverse cosine)
- cosh (hyperbolic cosine)
- acosh (inverse hyperbolic cosine)
- sin (sine)
- asin (inverse sine)
- sinh (hyperbolic sine)
- asinh (inverse hyperbolic sine)
- sec (secant)
- asec (inverse secant)
- sech (hyperbolic secant)
- asech (inverse hyperbolic secant)
- csc (cosecant)
- acsc (inverse cosecant)
- csch (hyperbolic secant)
- acsch (inverse hyperbolic secant)
- tan (tangent)
- atan (inverse tangent)
- tanh (hyperbolic tangent)
- atanh (inverse hyperbolic tangent)
- cot (cotangent)
- acot (inverse cotangent)
- coth (hyperbolic cotangent)
- acoth (inverse hyperbolic cotangent)
- sqrt (square root)
- exp (exponential)
- ln (natural log)
- log10 (base-10 log)
- log2 (base-2 log)
- pow (raised to the power of a real number)

---

Usage
=====

[](#usage)

To create a new complex object, you can provide either the real, imaginary and suffix parts as individual values, or as an array of values passed passed to the constructor; or a string representing the value. e.g

```
$real = 1.23;
$imaginary = -4.56;
$suffix = 'i';

$complexObject = new Complex\Complex($real, $imaginary, $suffix);

```

or

```
$real = 1.23;
$imaginary = -4.56;
$suffix = 'i';

$arguments = [$real, $imaginary, $suffix];

$complexObject = new Complex\Complex($arguments);

```

or

```
$complexString = '1.23-4.56i';

$complexObject = new Complex\Complex($complexString);

```

Complex objects are immutable: whenever you call a method or pass a complex value to a function that returns a complex value, a new Complex object will be returned, and the original will remain unchanged. This also allows you to chain multiple methods as you would for a fluent interface (as long as they are methods that will return a Complex result).

Performing Mathematical Operations
----------------------------------

[](#performing-mathematical-operations)

To perform mathematical operations with Complex values, you can call the appropriate method against a complex value, passing other values as arguments

```
$complexString1 = '1.23-4.56i';
$complexString2 = '2.34+5.67i';

$complexObject = new Complex\Complex($complexString1);
echo $complexObject->add($complexString2);

```

or pass all values to the appropriate function

```
$complexString1 = '1.23-4.56i';
$complexString2 = '2.34+5.67i';

echo Complex\add($complexString1, $complexString2);

```

If you want to perform the same operation against multiple values (e.g. to add three or more complex numbers), then you can pass multiple arguments to any of the operations.

You can pass these arguments as Complex objects, or as an array or string that will parse to a complex object.

Using functions
---------------

[](#using-functions)

When calling any of the available functions for a complex value, you can either call the relevant method for the Complex object

```
$complexString = '1.23-4.56i';

$complexObject = new Complex\Complex($complexString);
echo $complexObject->sinh();

```

or you can call the function as you would in procedural code, passing the Complex object as an argument

```
$complexString = '1.23-4.56i';

$complexObject = new Complex\Complex($complexString);
echo Complex\sinh($complexObject);

```

When called procedurally using the function, you can pass in the argument as a Complex object, or as an array or string that will parse to a complex object.

```
$complexString = '1.23-4.56i';

echo Complex\sinh($complexString);

```

In the case of the `pow()` function (the only implemented function that requires an additional argument) you need to pass both arguments when calling the function procedurally

```
$complexString = '1.23-4.56i';

$complexObject = new Complex\Complex($complexString);
echo Complex\pow($complexObject, 2);

```

or pass the additional argument when calling the method

```
$complexString = '1.23-4.56i';

$complexObject = new Complex\Complex($complexString);
echo $complexObject->pow(2);

```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 82.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~54 days

Recently: every ~38 days

Total

20

Last Release

1934d ago

Major Versions

1.4.8 → 2.0.x-dev2020-08-26

PHP version history (4 changes)1.0.0PHP ^5.6.0|^7.0.0

2.0.x-devPHP ^7.2 || ^8.0

1.5.x-devPHP ^5.6.0|^7.0

1.4.9PHP ^5.5.9|^7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/15cced701d409e0e42c113709bf93733bb0c7032c9267e7f8331de8f19582238?d=identicon)[Mykola Ivashchuk](/maintainers/Mykola%20Ivashchuk)

---

Top Contributors

[![jrfnl](https://avatars.githubusercontent.com/u/663378?v=4)](https://github.com/jrfnl "jrfnl (23 commits)")[![mykola-ivashchuk-gl](https://avatars.githubusercontent.com/u/75077777?v=4)](https://github.com/mykola-ivashchuk-gl "mykola-ivashchuk-gl (5 commits)")

---

Tags

mathematicscomplex

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mykola-ivashchuk-gl-complex/health.svg)

```
[![Health](https://phpackages.com/badges/mykola-ivashchuk-gl-complex/health.svg)](https://phpackages.com/packages/mykola-ivashchuk-gl-complex)
```

###  Alternatives

[markbaker/complex

PHP Class for working with complex numbers

1.7k283.1M38](/packages/markbaker-complex)[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[markbaker/matrix

PHP Class for working with matrices

1.5k279.7M38](/packages/markbaker-matrix)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M40](/packages/markrogoyski-math-php)[aza/math

AzaMath - Anizoptera CMF mathematic component. Arbitrary precision arithmetic (for huge integers; BCMath wrapper) and universal convertor between positional numeral systems (supported bases from 2 to 62 inclusive, and systems with custom alphabet; pure PHP realisation, can use GMP and core PHP functions for speed optimization).

1921.9k1](/packages/aza-math)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
