Skip to main content

MPComplex

MPComplex is a data type which support complex numbers which allow comparison and sorting operations. This library extends 'mpc' in 'mpmath' library (https://pypi.org/project/mpmath/) by allowing comparisons and sorting.

MPComplex Operations

The operations supported by MPComplex are addition, subtraction, multiplication, division, power, comparisons, and sorting.

Addition

Input: MPComplex(4, 2) + MPComplex(5, 3) Output: MPComplex(9, 5)

Subtraction

Input: MPComplex(7, 9) - MPComplex(3, 3) Output: MPComplex(4, 6)

Multiplication

Input: MPComplex(5, 4) * MPComplex(4, 6) Output: MPComplex(-4, 46)

Division

Input: MPComplex(5, 4) / MPComplex(4, 6) Output: MPComplex(0.846153846153846, -0.269230769230769)

Integer Division

Input: MPComplex(5, 4) // MPComplex(4, 6) Output: MPComplex(0, 0)

Power

Input: MPComplex(4, 2) ** 5 Output: MPComplex(-1216, 1312)

Comparisons in General

MPComplex objects are compared to each other in the following order:

  1. real part value
  2. imaginary part value

For example, to check whether MPComplex object a is greater than MPComplex object b or not, the program does the following steps:

  1. Checks if the real part of a is greater than the real part of b or not. If yes, 'True' is returned.
  2. If the real part of a is equal to the real part of b, go to step 3. Else, go to step 4.
  3. Return true if the imaginary part of a is greater than the imaginary part of b. Else, return 'False'.
  4. Return 'False' immediately.

The similar process applies to the operations 'less than', 'less than or equal to', and 'greater than or equal to' as well.

For checking equality of two complex numbers, equality applies if the real and imaginary parts of both numbers are equal.

Greater Than

Input: MPComplex(5, 4) > MPComplex(4, 6) Output: True

Greater Than or Equal To

Input: MPComplex(5, 4) >= MPComplex(4, 6) Output: True

Less Than

Input: MPComplex(5, 4) < MPComplex(4, 6) Output: False

Less Than or Equal To

Input: MPComplex(5, 4) <= MPComplex(4, 6) Output: False

Equal To

Input: MPComplex(4, 2) == MPComplex(4, 1) Output: False

Not Equal To

Input: MPComplex(4, 2) != MPComplex(4, 1) Output: True

Sorting

If a list of MPComplex objects is called with sort() method, the list will be sorted in ascending order.

Input: [MPComplex(4, 2), MPComplex(4, 1), MPComplex(5, 3), MPComplex(2, 7)].sort() Output: [MPComplex(2, 7), MPComplex(4, 1), MPComplex(4, 2), MPComplex(5, 3)]

Release files for MPComplex 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MPComplex 1.1
File Size Uploaded
MPComplex-1.1.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for MPComplex 1.1
File Interpreter ABI Platform
MPComplex-1.1-py2-none-any.whl Python 2 none any Details

Total release size: 10.0 kB

Release files / MPComplex-1.1.tar.gz

Download URL MPComplex-1.1.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2ce536d63ae1203ddcd54874a9ec360899b0c11dbb5352a063cbac15f2e893b4
BLAKE2b-256 checksum
How to use checksums
ab034d810eb5b8c4473b3c19e97a2b8f807aa46dd0153d5832bcb8c147d5e30e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4

Release files / MPComplex-1.1-py2-none-any.whl

Download URL MPComplex-1.1-py2-none-any.whl
Size 5.8 kB
Tags Python 2
SHA-256 checksum
How to use checksums
d17d7da2af0b2f3947c2c1c7d920e6d638f71ea1a36f7caa8c83b485e7c1e7e3
BLAKE2b-256 checksum
How to use checksums
e6182fe93f795a386d749830d174cabce317df08dbfc762320c07e536916964b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.4

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files

1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page