summaryrefslogtreecommitdiff
path: root/src/poly.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/poly.rs')
-rw-r--r--src/poly.rs27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/poly.rs b/src/poly.rs
index 7d964a4..9c70048 100644
--- a/src/poly.rs
+++ b/src/poly.rs
@@ -3,6 +3,7 @@ mod iter;
use crate::number::Number;
use iter::Iter;
use std::ops::{Add, Div, Mul, Sub};
+use std::fmt;
#[derive(PartialEq, Debug, Clone)]
pub struct Poly {
@@ -29,7 +30,7 @@ impl Poly {
}
}
- fn degree(&self) -> usize {
+ pub fn degree(&self) -> usize {
self.degree
}
@@ -109,21 +110,17 @@ impl Div for &Poly {
}
}
-pub fn gcd(a: &Poly, b: &Poly) -> Poly {
- let (_, c) = a / b;
- if c.is_zero() {
- b.clone()
- } else {
- gcd(b, &c)
- }
-}
-
-pub fn derivative(p: &Poly) -> Poly {
- let mut v = vec![0.0; p.degree()];
- for i in 0..v.len() {
- v[i] = p.data[i + 1] * (i + 1) as Number;
+impl fmt::Display for &Poly {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let mut s = String::new();
+ for i in 0..self.data.len() {
+ s.push_str(&self.data[i].clone().to_string());
+ if i < self.data.len() - 1 {
+ s.push_str(", ");
+ }
+ }
+ write!(f, "{}", s)
}
- Poly::new(v)
}
#[cfg(test)]