Skip to main content

A small library for solving quadratic (and linear) equations, including complex roots.

Project description

mathemagics

A tiny library for solving quadratic (and linear) equations of the form ax^2 + bx + c = 0, including complex roots.

Install

pip install mathemagics

Usage

from mathemagics import solve_quadratic

x1, x2 = solve_quadratic(1, -3, 2)
print(x1, x2)  # 2.0 1.0

Return value

solve_quadratic(a, b, c) returns a tuple (x1, x2):

  • If a == 0 and b == 0: no solution exists; returns (nan, nan).
  • If a == 0 and b != 0: the equation is linear; x1 and x2 are equal.
  • If a != 0 and the discriminant is non-negative: x1 and x2 are real numbers.
  • If a != 0 and the discriminant is negative: x1 and x2 are complex roots, each represented as a (real_part, imaginary_part) tuple.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mathemagics-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mathemagics-0.1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file mathemagics-0.1.0.tar.gz.

File metadata

  • Download URL: mathemagics-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for mathemagics-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e14e0002958de738a04a5d78127f88550dc6c42f1f0a8b4e7c57c37dd2ab1f0d
MD5 54eb6b77e3ba1a497fd6d20966f648c8
BLAKE2b-256 24d241ad14662251fb6b4c3f1e3fe6140320142393c89422dfb1ab9e03763db4

See more details on using hashes here.

File details

Details for the file mathemagics-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mathemagics-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for mathemagics-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c65e68ecd0a7d9fb050fa079a04be6e0bb5057f6edff6c688aa1bb10cef9fba8
MD5 c1fdb8fa965430981d9efede99d11b42
BLAKE2b-256 b157d95a5840831995ebc8e034b57755b36ee4597dee05a0f6821e9da4f00719

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page