RRootEquinox
Product

Product features · Stable quadratic roots

01

Keep widely separated coefficient scales beside the proposed root calculation and examine rejection paths together with the polynomial residuals.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Stable quadratic roots

● ● ●RootEquinox●
A concrete starting point · Stable quadratic roots ×
from math import isfinite, sqrt, copysign
def real_roots(a, b, c):
    original = (a, b, c)
    if not all(type(v) in (int, float) and isfinite(v) for v in original) or a == 0:
        raise ValueError("finite quadratic coefficients")
    if c == 0:
        other = -b / a
        if not isfinite(other) or (b != 0 and other == 0):
            raise ValueError("unrepresentable root")
        return [0.0] if b == 0 else sorted((0.0, other))
    scale = max(map(abs, original))
    a, b, c = (v / scale for v in original)
    if any(v != 0 and s == 0 for v, s in zip(original, (a,b,c))):
        raise ValueError("coefficient underflow")
    d = b*b - 4*a*c
    if d < 0: return []
    if d == 0: roots = [-b / (2*a)]
    else:
        q = -0.5 * (b + copysign(sqrt(d), b))
        if q == 0: raise ValueError("root underflow")
        roots = sorted((q/a, c/q))
    if not all(map(isfinite, roots)) or (original[2] != 0 and 0 in roots):
        raise ValueError("unrepresentable roots")
    return roots
✳Compute real roots of a quadratic using scaled coefficients and a cancellation-resistant formula.
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗