npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@rawify/rootfinder

v0.0.4

Published

The RAW root finder library for quadratic and cubic polynomials

Readme

RootFinder.js

NPM Package MIT license

RootFinder.js is a lightweight JavaScript library for finding the roots of quadratic equations and cubic equations. It leverages the Complex.js library to handle complex solutions, ensuring precision and correctness when dealing with both real and complex numbers.

Features

  • Solve quadratic equations of the form ax² + bx + c = 0.
  • Solve cubic equations of the form ax³ + bx² + cx + d = 0 using Cardano's method.
  • Support for complex roots using Complex.js.

Installation

You can install RootFinder.js via npm:

npm install @rawify/rootfinder

Or with yarn:

yarn add @rawify/rootfinder

Alternatively, download or clone the repository:

git clone https://github.com/rawify/RootFinder.js

Usage

Include the rootfinder.min.js file in your project:

<script src="path/to/rootfinder.min.js"></script>
<script src="path/to/complex.min.js"></script>
<script>
  const roots = RootFinder.quadratic(2, 5, 6);
  ...
</script>

Or in a Node.js project:

const RootFinder = require('@rawify/rootfinder');

or

import RootFinder from '@rawify/rootfinder';

Solving Quadratic Equations

To find the roots of a quadratic equation ax² + bx + c = 0:

const roots = RootFinder.quadratic(1, -3, 2);
console.log(roots); // Output: [ Complex { re: 2 }, Complex { re: 1 } ]

If the equation has complex roots:

const complexRoots = RootFinder.quadratic(1, 0, 1);
console.log(complexRoots); // Output: [ Complex { re: 0, im: 1 }, Complex { re: 0, im: -1 } ]

Solving Cubic Equations

To find the roots of a cubic equation ax³ + bx² + cx + d = 0:

const roots = RootFinder.cubic(1, -6, 11, -6);
console.log(roots); // Output: [ Complex { re: 1 }, Complex { re: 2 }, Complex { re: 3 } ]

For cubic equations with complex roots:

const complexRoots = RootFinder.cubic(1, 0, 0, -1);
console.log(complexRoots); // Output: [ Complex { re: 1, im: 0 }, Complex { re: -0.5, im: 0.866 }, Complex { re: -0.5, im: -0.866 } ]

API

quadratic(a, b, c[, returnReal=false])

Solves the quadratic equation ax² + bx + c = 0.

  • Parameters:

    • a (Number): Coefficient of
    • b (Number): Coefficient of x
    • c (Number): Constant term
    • returnReal (optional Boolean): Decide if only real roots should be returned
  • Returns: An array of roots, which can contain real or complex numbers.

cubic(a, b, c, d[, returnReal=false])

Solves the cubic equation ax³ + bx² + cx + d = 0 using Cardano's method.

  • Parameters:

    • a (Number): Coefficient of
    • b (Number): Coefficient of
    • c (Number): Coefficient of x
    • d (Number): Constant term
    • returnReal (optional Boolean): Decide if only real roots should be returned
  • Returns: An array of roots, which can contain real or complex numbers.

Coding Style

As every library I publish, RootFinder.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.

Building the library

After cloning the Git repository run:

npm install
npm run build

Run a test

Testing the source against the shipped test suite is as easy as

npm run test

Copyright and Licensing

Copyright (c) 2025, Robert Eisele Licensed under the MIT license.