from __future__ import annotations

from typing import List, Optional

import numpy as np

EPS = 1e-6


def double_equality(a, b) -> bool:
  return abs(a - b) < EPS


def iszero(x) -> bool:
  return double_equality(np.sum(x), 0)


def minpos_criterion(x: float) -> bool:
  return x is not None and not iszero(x) and x > 0


def minpos(args) -> Optional[float]:
  args = list(filter(minpos_criterion, args))

  if not args:
    return None

  return min(args)


def solve_quadratic(a, b, c) -> List[float]:
  if iszero(a):
    if iszero(b):
      return []

    return [-c / b]

  D = b ** 2 - 4 * a * c

  if iszero(D):
    return [-b / 2 / a]

  if D < 0:
    return []

  return [(-b - np.sqrt(D)) / 2 / a, (-b + np.sqrt(D)) / 2 / a]
