From 0c9405ed89a82b6963f580c727c89a4c3f150e9a Mon Sep 17 00:00:00 2001
From: Carl Philipp Klemm <philipp@uvos.xyz>
Date: Tue, 25 Apr 2023 14:13:41 +0200
Subject: [PATCH] switch fvalue to float, fix compile issues and warnings
 steming from change in sizeof(fvalue)

---
 basicmath.cpp          | 6 +++---
 eisgenerator/eistype.h | 2 +-
 eistype.cpp            | 9 ++++++++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/basicmath.cpp b/basicmath.cpp
index 1cf1b7d..389c55d 100644
--- a/basicmath.cpp
+++ b/basicmath.cpp
@@ -121,10 +121,10 @@ std::vector<eis::DataPoint> eis::rescale(const std::vector<eis::DataPoint>& data
 	std::vector<eis::DataPoint> output(outputSize);
 	for(size_t i = 0; i < output.size(); ++i)
 	{
-		double position = static_cast<double>(i) / (output.size()-1);
-		double sourcePosF = (data.size()-1)*position;
+		fvalue position = static_cast<double>(i) / (output.size()-1);
+		fvalue sourcePosF = (data.size()-1)*position;
 		size_t sourcePos = (data.size()-1)*position;
-		double frac = sourcePosF - sourcePos;
+		fvalue frac = sourcePosF - sourcePos;
 		output[i].im = data[sourcePos].im*(1-frac) + data[sourcePos+1].im*frac;
 		output[i].omega = data[sourcePos].omega*(1-frac) + data[sourcePos+1].omega*frac;
 	}
diff --git a/eisgenerator/eistype.h b/eisgenerator/eistype.h
index ae87ff9..1610370 100644
--- a/eisgenerator/eistype.h
+++ b/eisgenerator/eistype.h
@@ -5,7 +5,7 @@
 #include <cmath>
 #include <filesystem>
 
-typedef double fvalue;
+typedef float fvalue;
 
 namespace eis
 {
diff --git a/eistype.cpp b/eistype.cpp
index 9fa8635..ea4f9a9 100644
--- a/eistype.cpp
+++ b/eistype.cpp
@@ -53,7 +53,14 @@ EisSpectra eis::loadFromDisk(const std::filesystem::path& path)
 		tokens = tokenize(line, ',');
 		if(tokens.size() != 3)
 			throw file_error("invalid line in " + path.string() + ": " + line);
-		out.data.push_back(DataPoint({std::stod(tokens[1]), std::stod(tokens[2])}, std::stod(tokens[0])));
+
+		#pragma GCC diagnostic push
+		#pragma GCC diagnostic ignored "-Wnarrowing"
+		if constexpr (std::is_same<fvalue, double>::value)
+			out.data.push_back(DataPoint({std::stod(tokens[1]), std::stod(tokens[2])}, std::stod(tokens[0])));
+		else
+			out.data.push_back(DataPoint({std::stof(tokens[1]), std::stof(tokens[2])}, std::stof(tokens[0])));
+		#pragma GCC diagnostic pop
 	}
 
 	file.close();
-- 
GitLab