JSPM

quadratic-roots

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q19920F
  • License MIT

Compute the real roots of a quadratic equation in a numerically stable manner

Package Exports

  • quadratic-roots

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (quadratic-roots) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

quadratic-roots

Build Status npm version

Compute the real roots of a quadratic equation in a numerically stable manner

Introduction

In floating point arithmetic, the naive method for determining the roots of a quadratic equation ("x equals negative b, plus or minus etc.") may lead to severe cancellation and an inaccurate result.

Sample usage:

var roots = require('quadratic-roots')

roots(0,0,0)   // --> []
roots(0,0,6)   // --> []
roots(0,2,6)   // --> [-3]
roots(1,1,-12) // --> [-4,3]
roots(1,-4,4)  // --> [2,2]
roots(1,0,1)   // --> []

Install

$ npm install quadratic-roots

API

require('quadratic-roots')( a, b, c )

Compute the roots of the polynomial ax^2 + bx + c = 0.

Returns

  • If no roots, returns an empty array []
  • If a linear equation, returns one root
  • If a parabola with no real roots, returns an empty array
  • If a parabola with one root multiplicity 2, returns an array with the same root twice
  • Otherwise returns an array with two real roots

Credits

(c) 2015 Ricky Reusser. MIT License