Browse Source

Remove -ffast-math from compiler FLAGS. Fix display value of "-0" in tooltip.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
3489859fe8
4 changed files with 40 additions and 19 deletions
  1. +3
    -1
      compile.mk
  2. +5
    -0
      include/math.hpp
  3. +3
    -18
      include/ui/Quantity.hpp
  4. +29
    -0
      src/ui/Quantity.cpp

+ 3
- 1
compile.mk View File

@@ -8,9 +8,11 @@ OBJCOPY ?= objcopy

# Generate dependency files alongside the object files
FLAGS += -MMD -MP
# Debugger symbols. These are removed with `strip`.
FLAGS += -g
# Optimization
FLAGS += -O3 -march=nocona -ffast-math -fno-finite-math-only
FLAGS += -O3 -march=nocona
# Warnings
FLAGS += -Wall -Wextra -Wno-unused-parameter

ifneq ($(ARCH), mac)


+ 5
- 0
include/math.hpp View File

@@ -103,6 +103,11 @@ inline float sgn(float x) {
return x > 0.f ? 1.f : x < 0.f ? -1.f : 0.f;
}

/** Converts -0.f to 0.f. Leaves all other values unchanged. */
inline float normalizeZero(float x) {
return x + 0.f;
}

inline float eucMod(float a, float base) {
float mod = std::fmod(a, base);
return (mod >= 0.0f) ? mod : mod + base;


+ 3
- 18
include/ui/Quantity.hpp View File

@@ -1,7 +1,6 @@
#pragma once
#include "ui/common.hpp"
#include "math.hpp"
#include "string.hpp"


namespace rack {
@@ -46,16 +45,9 @@ struct Quantity {
virtual int getDisplayPrecision() {return 2;}

/** Returns a string representation of the display value */
virtual std::string getDisplayValueString() {
return string::f("%.*f", getDisplayPrecision(), getDisplayValue());
}
virtual std::string getDisplayValueString();

virtual void setDisplayValueString(std::string s) {
float displayValue = 0.f;
int n = std::sscanf(s.c_str(), "%f", &displayValue);
if (n == 1)
setDisplayValue(displayValue);
}
virtual void setDisplayValueString(std::string s);

/** The name of the quantity */
virtual std::string getLabel() {return "";}
@@ -66,14 +58,7 @@ struct Quantity {
virtual std::string getUnit() {return "";}

/** Returns a string representation of the quantity */
virtual std::string getString() {
std::string s;
std::string label = getLabel();
if (!label.empty())
s += label + ": ";
s += getDisplayValueString() + getUnit();
return s;
}
virtual std::string getString();

// Helper methods



+ 29
- 0
src/ui/Quantity.cpp View File

@@ -0,0 +1,29 @@
#include "ui/Quantity.hpp"
#include "string.hpp"


namespace rack {


std::string Quantity::getDisplayValueString() {
return string::f("%.*f", getDisplayPrecision(), math::normalizeZero(getDisplayValue()));
}

void Quantity::setDisplayValueString(std::string s) {
float displayValue = 0.f;
int n = std::sscanf(s.c_str(), "%f", &displayValue);
if (n == 1)
setDisplayValue(displayValue);
}

std::string Quantity::getString() {
std::string s;
std::string label = getLabel();
if (!label.empty())
s += label + ": ";
s += getDisplayValueString() + getUnit();
return s;
}


} // namespace rack

Loading…
Cancel
Save