From 6911c1eb5ff05d1fb90b3f0ba66947163331701d Mon Sep 17 00:00:00 2001
From: Stephen D <webmaster@scd31.com>
Date: Fri, 4 Feb 2022 22:32:29 -0400
Subject: [PATCH] add mag_squared

---
 Cargo.toml |  2 +-
 src/lib.rs | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 3facea8..0363e15 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 edition = "2021"
 name = "goertzel-nostd"
-version = "0.1.0"
+version = "0.2.0"
 authors = ["Stephen D"]
 repository = "https://github.com/mcpherrinm/goertzel.git"
 keywords = ["dsp", "goertzel", "fft", "fourier"]
diff --git a/src/lib.rs b/src/lib.rs
index 1c4486e..5a646a9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -49,6 +49,10 @@ impl Parameters {
 	pub fn mag(self, samples: &[f32]) -> f32 {
 		self.start().add_samples(samples).finish_mag()
 	}
+
+	pub fn mag_squared(self, samples: &[f32]) -> f32 {
+		self.start().add_samples(samples).finish_mag_squared()
+	}
 }
 
 impl Partial {
@@ -69,8 +73,12 @@ impl Partial {
 	}
 
 	pub fn finish_mag(self) -> f32 {
+		libm::sqrtf(self.finish_mag_squared())
+	}
+
+	pub fn finish_mag_squared(self) -> f32 {
 		let (real, imag) = self.finish();
-		libm::sqrtf(real * real + imag * imag)
+		real * real + imag * imag
 	}
 }
 
-- 
GitLab