quadraticequationsolver

Robust High-Precision Quadratic Equation Solver

https://github.com/kanition/quadraticequationsolver

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.1%) to scientific vocabulary

Keywords

catastrophic-cancellation floating-point numerical-calculation overflow quadratic-equation underflow
Last synced: 6 months ago · JSON representation ·

Repository

Robust High-Precision Quadratic Equation Solver

Basic Info
  • Host: GitHub
  • Owner: kanition
  • License: apache-2.0
  • Language: C++
  • Default Branch: main
  • Homepage:
  • Size: 4.72 MB
Statistics
  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
catastrophic-cancellation floating-point numerical-calculation overflow quadratic-equation underflow
Created 9 months ago · Last pushed 6 months ago
Metadata Files
Readme Contributing License Code of conduct Citation

README.md

https://github.com/kanition/QuadraticEquationSolver

C++ GitHub License GitHub Actions Workflow Status

A Robust High-Precision Quadratic Equation Solver in C++20 for math ax^2+bx+c=0, where $a,b,c$ and $x$ are all real numbers in the Floating-Point format, under IEEE Standard for Floating-Point Arithmetic (IEEE 754).

Both single-precision (32-bits) and double-precision (64-bits) are supported.

Quick Start

To use this solver in your project, you can: 1. Include the header file QuadraticEquationSolver.h; 2. Initialize a QuadraticEquationSolver with $a,b,c$; 3. Call the solver method solve to get the roots and state! ```cpp

include "QuadraticEquationSolver.h"

double a = 1.0, b = 4.0, c = -5.0; QuadtraticEquationSolver solver(a, b, c);

double x1, x2; // x1 and x2 will be the two roots! And s is their state. SolverState s = solver.solve(x1, x2); ```

  1. Print the roots and state; ```cpp #include

std::cout << "x1: " << x1 << std::endl; std::cout << "x2: " << x2 << std::endl;

// Print the state of the solver itself std::cout << "State: " << solver.printsolverstate() << std::endl;

// Or print the specified state s by the class static method std::cout << "State: " << QuadtraticEquationSolver::printsolverstate(s) << std::endl; ```

  1. You can re-use the solver by reset: cpp a = 1.0, b = 4.0, c = 4.0; solver.reset(a, b, c); // Clean the solver state and reset a, b, c s = solver.solve(x1, x2); // Solve the new equation

Compile and Run Demo

Requirements: * CMake >= 3.20 * C++ compiler supporting C++20 standard. ```bash

Make a directory OUTSIDE this source directory and go into it

mkdir ../build cd ../build

Use cmake to configure the project with this SOURCE DIRECTORY

cmake ../QuadtraticEquationSolver

Compile

make

Run the demo

./demo

Optional: run the test

make test

Optional: Compare QuadtraticEquationSolver and a naive non-robust solver

./floattest # For 41 single-precision (32-bits) cases ./doubletest # For 41 double-precision (64-bits) cases ```

Robustness & Precision

See here for more detailed discussion and surprising cases.

Acknowledgement

About Algorithm

Thank the author for developing and sharing this algorithm in the following paper. Frédéric Goualard. The Ins and Outs of Solving Quadratic Equations with Floating-Point Arithmetic. 2023. ⟨hal-04116310⟩

About Banner

Based on works by wepik@Freepik

LICENSE

Copyright 2025 Kanition

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Owner

  • Name: Kanition
  • Login: kanition
  • Kind: user
  • Location: Snezhnaya

No matter what happens in the future, please don't regret meeting me.

Citation (CITATION.cff)

# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!

cff-version: 1.2.0
title: Robust High-Precision Quadratic Equation Solver
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - family-names: Kanition
repository-code: 'https://github.com/kanition/QuadraticEquationSolver'
abstract: >-
  A robust high-precision quadratic equation solver in C++20
  in the floating-point format, under IEEE Standard for
  Floating-Point Arithmetic (IEEE 754). Both
  single-precision (32-bits) and double-precision (64-bits)
  are supported.
keywords:
  - quadratic equation
  - floating-point
  - numerical calculation
  - catastrophic cancellation
  - overflow
  - underflow
license: Apache-2.0
date-released: '2025-06-06'

GitHub Events

Total
  • Push event: 8
  • Public event: 1
Last Year
  • Push event: 8
  • Public event: 1

Issues and Pull Requests

Last synced: 9 months ago

All Time
  • Total issues: 0
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

.github/workflows/cmake-multi-platform.yml actions
  • actions/checkout v4 composite