{"id":14583,"library":"flo-poly","title":"FloPoly Polynomial Utility","description":"FloPoly is a JavaScript/TypeScript utility library focused on efficient and accurate real root-finding for real-coefficient polynomials. Currently at version 7.0.1, it supports Node.js (>=12.20.0) and browser environments, distributed as an ECMAScript Module (ESM). The library excels in root-finding for polynomials up to approximately degree 20, employing Rolle's Theorem. It offers advanced capabilities like 'certified' root-finding, which are robust against high condition numbers, and supports various coefficient precisions including `double`, `double-double`, `Shewchuk expansions`, and `bigint`. Beyond root-finding, FloPoly provides a suite of polynomial operators. Its ESM-only distribution simplifies its use in modern JavaScript projects, though it marks a breaking change for older CommonJS environments. While a precise release cadence is not specified, the version jumps suggest significant, though not frequent, updates.","status":"active","version":"7.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/FlorisSteenkamp/FloPoly","tags":["javascript","polynomial","roots","root","finding","typescript"],"install":[{"cmd":"npm install flo-poly","lang":"bash","label":"npm"},{"cmd":"yarn add flo-poly","lang":"bash","label":"yarn"},{"cmd":"pnpm add flo-poly","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"FloPoly is ESM-only. CommonJS `require` is not supported. Use named ESM imports.","wrong":"const { allRoots } = require('flo-poly');","symbol":"allRoots","correct":"import { allRoots } from 'flo-poly';"},{"note":"This is a named export, not a default export. Ensure you destructure it correctly.","wrong":"import allRootsCertifiedSimplified from 'flo-poly';","symbol":"allRootsCertifiedSimplified","correct":"import { allRootsCertifiedSimplified } from 'flo-poly';"},{"note":"Used for polynomial addition; demonstrates a general polynomial operator import.","symbol":"add","correct":"import { add } from 'flo-poly';"},{"note":"When using directly in browsers without a bundler, you must import from the pre-bundled path. The bare specifier `flo-poly` only works with bundlers or Node.js module resolution.","wrong":"import { allRoots } from 'flo-poly';","symbol":"allRoots (browser)","correct":"import { allRoots } from './node_modules/flo-poly/browser/index.min.js';"}],"quickstart":{"code":"import { allRoots, allRootsCertifiedSimplified, add } from 'flo-poly';\n\n// Example 1: Finding roots of a double-precision polynomial\nconst p1 = [1, -21, 175, -735, 1624, -1764, 720]; // x^6 - 21x^5 + ... + 720\nconst roots1 = allRoots(p1);\nconsole.log('Roots (approximate):', roots1);\n\n// Example 2: Certified root finding for high accuracy\nconst p2 = [1, -21, 175, -735, 1624, -1764, 720];\nconst certifiedRoots = allRootsCertifiedSimplified(p2);\nconsole.log('Roots (certified simplified):', certifiedRoots);\n\n// Example 3: Polynomial addition\nconst polyA = [1, 2, 3]; // 1x^2 + 2x + 3\nconst polyB = [3, 4];   // 3x + 4\nconst sumPoly = add(polyA, polyB);\nconsole.log('Polynomial sum (1x^2 + 2x + 3) + (3x + 4):', sumPoly); // Expected: [1, 5, 7]\n\nif (roots1.length === 6 && sumPoly.length === 3) {\n    console.log('FloPoly functions executed successfully! 😁');\n} else {\n    console.log('Something went wrong. 😥');\n}","lang":"typescript","description":"Demonstrates basic root finding with `allRoots`, highly accurate certified root finding with `allRootsCertifiedSimplified`, and a simple polynomial addition operation."},"warnings":[{"fix":"Ensure your project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json`) and use `import` statements. If using bundlers like Webpack with TypeScript, specific configurations like `resolve-typescript-plugin` might be necessary.","message":"FloPoly is an ESM-only package since version 1.0.0 (or possibly earlier, certainly by 7.x.x). This means it cannot be `require()`-d in CommonJS environments without a transpilation step or a dynamic `import()` call, which may be slower.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For highly accurate and certified results, especially with ill-conditioned polynomials, use `allRootsCertifiedSimplified` or the more flexible `allRootsCertified` which supports `double-double` and `Shewchuk expansion` coefficients.","message":"The `allRoots` function does not account for error bounds and can yield inaccurate results for polynomials with high condition numbers.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider the degree of polynomials when choosing FloPoly for performance-critical applications, or evaluate alternative libraries if consistently dealing with very high-degree polynomials where `O(n)` methods are critical.","message":"The library's performance using Rolle's Theorem for root finding becomes asymptotically slower (`O(n²)`) for higher polynomial degrees, typically beyond degree 20, compared to `O(n)` methods like Descartes' Rule of Signs.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"If dealing with extremely large root magnitudes or coefficient values, utilize functions that support arbitrary-precision types like `bigint` or `double-double` where available within the library, or implement scaling pre-processing.","message":"Evaluating polynomials with large `|x|` values can lead to floating-point overflow, as standard double-precision numbers have a maximum value of approximately `1.8 x 10^308`.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your project is set up for ESM by adding `\"type\": \"module\"` to your `package.json` and using `import { ... } from 'flo-poly';`. If in a browser without a bundler, import from the explicit browser path: `import { ... } from './node_modules/flo-poly/browser/index.min.js';`","cause":"Attempting to use `require()` to import `flo-poly` in an ESM-only Node.js environment or a browser.","error":"ReferenceError: require is not defined"},{"fix":"Verify that `allRoots` is correctly imported as a named export: `import { allRoots } from 'flo-poly';`. FloPoly primarily uses named exports. If the issue persists with a bundler, ensure your bundler configuration correctly handles ESM imports, particularly for TypeScript projects where `resolve-typescript-plugin` might be needed.","cause":"This error typically occurs in a bundled environment (e.g., Webpack) when a CommonJS default export is incorrectly imported as a named ESM export, or vice-versa. Although FloPoly is ESM-only, incorrect import syntax can trigger similar errors. It could also happen if a module is incorrectly interpreted as having a default export when it only has named exports.","error":"TypeError: (0 , flo_poly__WEBPACK_IMPORTED_MODULE_0__.allRoots) is not a function"},{"fix":"For browsers, ensure your script tag is `<script type=\"module\">`. For Node.js, ensure your `package.json` includes `\"type\": \"module\"` to enable ESM globally, or run with `node --input-type=module` for single files.","cause":"Attempting to use `import` syntax in a browser `<script>` tag without `type=\"module\"` or in a Node.js environment that is configured for CommonJS.","error":"Uncaught SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}