summaryrefslogtreecommitdiff
path: root/src/poly.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/poly.rs')
-rw-r--r--src/poly.rs40
1 files changed, 4 insertions, 36 deletions
diff --git a/src/poly.rs b/src/poly.rs
index bae3a15..c76e481 100644
--- a/src/poly.rs
+++ b/src/poly.rs
@@ -1,18 +1,17 @@
mod iter;
-use crate::number::Number;
use iter::Iter;
use std::fmt;
use std::ops::{Add, Mul, Sub};
#[derive(PartialEq, Debug, Clone)]
pub struct Poly {
- data: Vec<Number>,
+ data: Vec<f32>,
degree: usize,
}
impl Poly {
- pub fn new(data: Vec<Number>) -> Poly {
+ pub fn new(data: Vec<f32>) -> Poly {
let mut i = data.len() - 1;
while data[i] == 0.0 && i > 0 {
i -= 1;
@@ -20,16 +19,6 @@ impl Poly {
Poly { data, degree: i }
}
- fn mono(degree: usize, coefficient: Number) -> Poly {
- if coefficient != 0.0 {
- let mut p = vec![0.0; degree + 1];
- p[degree] = coefficient;
- Poly::new(p)
- } else {
- Poly::new(vec![0.0])
- }
- }
-
pub fn degree(&self) -> usize {
self.degree
}
@@ -37,15 +26,6 @@ impl Poly {
fn iter(&self) -> Iter {
Iter::new(self.data.clone(), self.degree())
}
-
- fn is_zero(&self) -> bool {
- for i in 0..self.data.len() {
- if self.data[i] != 0.0 {
- return false;
- }
- }
- true
- }
}
impl Add for &Poly {
@@ -71,7 +51,7 @@ impl Mul for &Poly {
let mut r = Vec::new();
for i in 0..other.degree() + 1 {
let mut prefix = vec![0.0; i];
- let mut suffix: Vec<Number> = self
+ let mut suffix: Vec<f32> = self
.iter()
.take(self.degree() + 1)
.map(|x| x * other.data[i])
@@ -122,20 +102,8 @@ mod tests {
}
#[test]
- fn poly_is_zero() {
- let p = Poly::new(vec![0.0; 5]);
- assert_eq!(p.is_zero(), true);
- }
-
- #[test]
- fn poly_is_not_zero() {
- let p = Poly::mono(5, 8.0);
- assert_eq!(p.is_zero(), false);
- }
-
- #[test]
fn degree_is_five() {
- let p = Poly::mono(5, 2.0);
+ let p = Poly::new(vec![0.0, 0.0, 0.0, 0.0, 0.0, 2.0]);
assert_eq!(p.degree(), 5);
}