Skip to content

Commit

Permalink
perf: do not calculate square root when calculate modulus
Browse files Browse the repository at this point in the history
  • Loading branch information
istudyatuni committed Jun 23, 2022
1 parent 4d431fe commit 5c0cd1e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub struct Mandelbrot {
pixels_count: usize,
}

const ESCAPE_MODULUS: f64 = 2.0;
/// 2^2
const ESCAPE_MODULUS: f64 = 4.0;
/// complex zero
const Z0: Complex<f64> = Complex::new(0.0, 0.0);

Expand Down Expand Up @@ -82,7 +83,8 @@ fn check_series(x: f64, i: f64, depth: u32) -> u32 {
let mut num = Z0 + point;

for step in 0..depth {
if num.norm() >= ESCAPE_MODULUS {
// do not calculate square root
if num.norm_sqr() >= ESCAPE_MODULUS {
return step;
}

Expand Down

0 comments on commit 5c0cd1e

Please sign in to comment.