# HG changeset patch # User Chris Cannam # Date 1425902530 0 # Node ID 31f01931b7816088aaa0ccac436fca30dc924603 # Parent fe39581d249b6f6b0c0216aadf5c8624ddf3ffbd Move to using double rather than float for floating-point calculations (float only for storage); more build fixes diff -r fe39581d249b -r 31f01931b781 base/Clipboard.cpp --- a/base/Clipboard.cpp Wed Mar 04 19:08:21 2015 +0000 +++ b/base/Clipboard.cpp Mon Mar 09 12:02:10 2015 +0000 @@ -15,7 +15,7 @@ #include "Clipboard.h" -Clipboard::Point::Point(long frame, QString label) : +Clipboard::Point::Point(sv_frame_t frame, QString label) : m_haveFrame(true), m_frame(frame), m_haveValue(false), @@ -31,7 +31,7 @@ { } -Clipboard::Point::Point(long frame, float value, QString label) : +Clipboard::Point::Point(sv_frame_t frame, float value, QString label) : m_haveFrame(true), m_frame(frame), m_haveValue(true), @@ -47,7 +47,7 @@ { } -Clipboard::Point::Point(long frame, float value, int duration, QString label) : +Clipboard::Point::Point(sv_frame_t frame, float value, sv_frame_t duration, QString label) : m_haveFrame(true), m_frame(frame), m_haveValue(true), @@ -63,7 +63,7 @@ { } -Clipboard::Point::Point(long frame, float value, int duration, float level, QString label) : +Clipboard::Point::Point(sv_frame_t frame, float value, sv_frame_t duration, float level, QString label) : m_haveFrame(true), m_frame(frame), m_haveValue(true), @@ -120,14 +120,14 @@ return m_haveFrame; } -long +sv_frame_t Clipboard::Point::getFrame() const { return m_frame; } Clipboard::Point -Clipboard::Point::withFrame(long frame) const +Clipboard::Point::withFrame(sv_frame_t frame) const { Point p(*this); p.m_haveFrame = true; @@ -162,14 +162,14 @@ return m_haveDuration; } -int +sv_frame_t Clipboard::Point::getDuration() const { return m_duration; } Clipboard::Point -Clipboard::Point::withDuration(int duration) const +Clipboard::Point::withDuration(sv_frame_t duration) const { Point p(*this); p.m_haveDuration = true; @@ -231,14 +231,14 @@ return m_haveReferenceFrame && (m_referenceFrame != m_frame); } -long +sv_frame_t Clipboard::Point::getReferenceFrame() const { return m_referenceFrame; } void -Clipboard::Point::setReferenceFrame(long f) +Clipboard::Point::setReferenceFrame(sv_frame_t f) { m_haveReferenceFrame = true; m_referenceFrame = f; diff -r fe39581d249b -r 31f01931b781 base/Clipboard.h --- a/base/Clipboard.h Wed Mar 04 19:08:21 2015 +0000 +++ b/base/Clipboard.h Mon Mar 09 12:02:10 2015 +0000 @@ -19,30 +19,32 @@ #include #include +#include "BaseTypes.h" + class Clipboard { public: class Point { public: - Point(long frame, QString label); - Point(long frame, float value, QString label); - Point(long frame, float value, int duration, QString label); - Point(long frame, float value, int duration, float level, QString label); + Point(sv_frame_t frame, QString label); + Point(sv_frame_t frame, float value, QString label); + Point(sv_frame_t frame, float value, sv_frame_t duration, QString label); + Point(sv_frame_t frame, float value, sv_frame_t duration, float level, QString label); Point(const Point &point); Point &operator=(const Point &point); bool haveFrame() const; - long getFrame() const; - Point withFrame(long frame) const; + sv_frame_t getFrame() const; + Point withFrame(sv_frame_t frame) const; bool haveValue() const; float getValue() const; Point withValue(float value) const; bool haveDuration() const; - int getDuration() const; - Point withDuration(int duration) const; + sv_frame_t getDuration() const; + Point withDuration(sv_frame_t duration) const; bool haveLabel() const; QString getLabel() const; @@ -55,22 +57,22 @@ bool haveReferenceFrame() const; bool referenceFrameDiffers() const; // from point frame - long getReferenceFrame() const; - void setReferenceFrame(long); + sv_frame_t getReferenceFrame() const; + void setReferenceFrame(sv_frame_t); private: bool m_haveFrame; - long m_frame; + sv_frame_t m_frame; bool m_haveValue; float m_value; bool m_haveDuration; - int m_duration; + sv_frame_t m_duration; bool m_haveLabel; QString m_label; bool m_haveLevel; float m_level; bool m_haveReferenceFrame; - long m_referenceFrame; + sv_frame_t m_referenceFrame; }; Clipboard(); diff -r fe39581d249b -r 31f01931b781 base/LogRange.cpp --- a/base/LogRange.cpp Wed Mar 04 19:08:21 2015 +0000 +++ b/base/LogRange.cpp Mon Mar 09 12:02:10 2015 +0000 @@ -21,7 +21,7 @@ #include void -LogRange::mapRange(float &min, float &max, float logthresh) +LogRange::mapRange(double &min, double &max, double logthresh) { if (min > max) std::swap(min, max); if (max == min) max = min + 1; @@ -30,19 +30,19 @@ if (min >= 0.f) { - max = log10f(max); // we know max != 0 + max = log10(max); // we know max != 0 if (min == 0.f) min = std::min(logthresh, max); - else min = log10f(min); + else min = log10(min); // SVDEBUG << "LogRange::mapRange: positive: min = " << min << ", max = " << max << endl; } else if (max <= 0.f) { - min = log10f(-min); // we know min != 0 + min = log10(-min); // we know min != 0 if (max == 0.f) max = std::min(logthresh, min); - else max = log10f(-max); + else max = log10(-max); std::swap(min, max); @@ -52,7 +52,7 @@ // min < 0 and max > 0 - max = log10f(std::max(max, -min)); + max = log10(std::max(max, -min)); min = std::min(logthresh, max); // SVDEBUG << "LogRange::mapRange: spanning: min = " << min << ", max = " << max << endl; @@ -61,21 +61,21 @@ if (min == max) min = max - 1; } -float -LogRange::map(float value, float thresh) +double +LogRange::map(double value, double thresh) { if (value == 0.f) return thresh; - return log10f(fabsf(value)); + return log10(fabs(value)); } -float -LogRange::unmap(float value) +double +LogRange::unmap(double value) { - return powf(10.0, value); + return pow(10.0, value); } static double -sd(const std::vector &values, int start, int n) +sd(const std::vector &values, int start, int n) { double sum = 0.f, mean = 0.f, variance = 0.f; for (int i = 0; i < n; ++i) { @@ -91,7 +91,7 @@ } bool -LogRange::useLogScale(std::vector values) +LogRange::useLogScale(std::vector values) { // Principle: Partition the data into two sets around the median; // calculate the standard deviation of each set; if the two SDs diff -r fe39581d249b -r 31f01931b781 base/LogRange.h --- a/base/LogRange.h Wed Mar 04 19:08:21 2015 +0000 +++ b/base/LogRange.h Mon Mar 09 12:02:10 2015 +0000 @@ -28,27 +28,27 @@ * extents of the logarithmic range. thresh is the minimum value * for the log range, to be used if the linear range spans zero. */ - static void mapRange(float &min, float &max, float thresh = -10); + static void mapRange(double &min, double &max, double thresh = -10); /** * Map a value onto a logarithmic range. This just means taking * the base-10 log of the absolute value, or using the threshold * value if the absolute value is zero. */ - static float map(float value, float thresh = -10); + static double map(double value, double thresh = -10); /** * Map a value from the logarithmic range back again. This just * means taking the value'th power of ten. */ - static float unmap(float value); + static double unmap(double value); /** * Estimate whether a set of values would be more properly shown * using a logarithmic than a linear scale. This is only ever * going to be a rough guess. */ - static bool useLogScale(std::vector values); + static bool useLogScale(std::vector values); }; diff -r fe39581d249b -r 31f01931b781 data/model/EditableDenseThreeDimensionalModel.cpp --- a/data/model/EditableDenseThreeDimensionalModel.cpp Wed Mar 04 19:08:21 2015 +0000 +++ b/data/model/EditableDenseThreeDimensionalModel.cpp Mon Mar 09 12:02:10 2015 +0000 @@ -27,6 +27,8 @@ #include #include +using std::vector; + #include "system/System.h" EditableDenseThreeDimensionalModel::EditableDenseThreeDimensionalModel(sv_samplerate_t sampleRate, @@ -445,15 +447,15 @@ { QReadLocker locker(&m_lock); - QVector sample; - QVector n; + vector sample; + vector n; for (int i = 0; i < 10; ++i) { int index = i * 10; if (index < m_data.size()) { const Column &c = m_data.at(index); - while (c.size() > sample.size()) { - sample.push_back(0.f); + while (c.size() > int(sample.size())) { + sample.push_back(0.0); n.push_back(0); } for (int j = 0; j < c.size(); ++j) { @@ -464,11 +466,11 @@ } if (sample.empty()) return false; - for (int j = 0; j < sample.size(); ++j) { - if (n[j]) sample[j] /= float(n[j]); + for (decltype(sample)::size_type j = 0; j < sample.size(); ++j) { + if (n[j]) sample[j] /= n[j]; } - return LogRange::useLogScale(sample.toStdVector()); + return LogRange::useLogScale(sample); } void