Skip to content

Commit e8035da

Browse files
committed
fixed the series approximation
1 parent 6cbaa22 commit e8035da

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

output.png

-497 KB
Loading

src/bin/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() {
6161
center_im,
6262
0.01,
6363
false,
64-
16
64+
64
6565
);
6666

6767
let time = Instant::now();

src/math/series_approximation.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ impl SeriesApproximation {
6767

6868
self.next_coefficients[0] = to_extended(&self.z);
6969
self.next_coefficients[1] = self.coefficients[0] * self.coefficients[1] * 2.0 + add_value;
70+
self.next_coefficients[0].reduce();
71+
self.next_coefficients[1].reduce();
7072

7173
// Calculate the new coefficents
7274
for k in 2..=self.order {
@@ -109,7 +111,8 @@ impl SeriesApproximation {
109111

110112
// Check to make sure that the derivative is greater than or equal to 1
111113
if derivative.to_float() < 1.0 {
112-
derivative = FloatExtended::new(1.0, 0);
114+
derivative.mantissa = 1.0;
115+
derivative.exponent = 0;
113116
}
114117

115118
// Check that the error over the derivative is less than the pixel spacing
@@ -189,6 +192,21 @@ impl SeriesApproximation {
189192
approximation
190193
}
191194

195+
fn evaluate_next(&self, point_delta: ComplexExtended) -> ComplexExtended {
196+
// 1907 ms packing opus 4K
197+
// Horner's rule
198+
let mut approximation = self.next_coefficients[self.order];
199+
200+
for k in (1..=(self.order - 1)).rev() {
201+
approximation *= point_delta;
202+
approximation += self.coefficients[k];
203+
}
204+
205+
approximation *= point_delta;
206+
approximation.reduce();
207+
approximation
208+
}
209+
192210
// pub fn evaluate_derivative(&self, point_delta: ComplexExtended) -> FloatExtended {
193211
// let mut original_point_derivative_n = ComplexExtended::new(1.0, 0, 0.0, 0);
194212
// let mut approximation_derivative = ComplexExtended::new(0.0, 0, 0.0, 0);

src/util/complex_extended.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,20 @@ pub struct ComplexExtended {
1111
}
1212

1313
impl ComplexExtended {
14-
// maybe set up different versions for these function if the reduce is needed
1514
#[inline]
1615
pub fn new(mantissa: Complex<f64>, exponent: i32) -> Self {
17-
let mut temp = ComplexExtended {
16+
ComplexExtended {
1817
mantissa,
1918
exponent
20-
};
21-
temp.reduce();
22-
temp
19+
}
2320
}
2421

2522
#[inline]
2623
pub fn new2(re: f64, im: f64, exponent: i32) -> Self {
27-
let mut temp = ComplexExtended {
24+
ComplexExtended {
2825
mantissa: Complex::<f64>::new(re, im),
2926
exponent
30-
};
31-
temp.reduce();
32-
temp
27+
}
3328
}
3429

3530
#[inline]

0 commit comments

Comments
 (0)