poly_cool/
lib.rs

1//! This is a crate for numerical polynomial root-finding.
2//!
3//! Currently, we implement a single solver: Yuksel's iterative algorithm
4//! for finding roots in a bounded interval. We aspire to have
5//! more, with thorough tests and benchmarks.
6
7mod cubic;
8mod poly;
9mod quadratic;
10
11#[cfg(any(test, feature = "arbitrary"))]
12pub mod arbitrary;
13
14// Cubic and Quadratic are used in benches so they have to be public.
15// We haven't actually put any thought into their API yet, though.
16#[doc(hidden)]
17pub use cubic::Cubic;
18#[doc(hidden)]
19pub use quadratic::Quadratic;
20
21pub use poly::Poly;
22
23trait TerminationCondition {
24    fn stop(&self, last_step: f64, value: f64) -> bool;
25}
26
27struct InputError(f64);
28
29impl TerminationCondition for InputError {
30    fn stop(&self, last_step: f64, _value: f64) -> bool {
31        last_step.abs() <= self.0
32    }
33}
34
35struct ValueError(f64);
36
37impl TerminationCondition for ValueError {
38    fn stop(&self, _last_step: f64, value: f64) -> bool {
39        value.abs() <= self.0
40    }
41}
42
43fn different_signs(x: f64, y: f64) -> bool {
44    (x < 0.0) != (y < 0.0)
45}