From 15892aa7bf7a4a76ddbd37eff3bec2ff55d90d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 15 Jun 2017 10:30:31 +0200 Subject: [PATCH] [apps] In graph and regression banner view, decrease the number of significant digits to avoid weird values as 0.3999999 Change-Id: I2d2b669d92c8ccb760cbff6bd64e8561755be9eb --- apps/constant.cpp | 1 + apps/constant.h | 1 + apps/graph/graph/graph_controller.cpp | 2 +- apps/regression/graph_controller.cpp | 6 +++--- apps/shared/function_graph_controller.cpp | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/constant.cpp b/apps/constant.cpp index 8b54a3aa0..6a1259964 100644 --- a/apps/constant.cpp +++ b/apps/constant.cpp @@ -1,4 +1,5 @@ #include "constant.h" constexpr int Constant::LargeNumberOfSignificantDigits; +constexpr int Constant::MediumNumberOfSignificantDigits; constexpr int Constant::ShortNumberOfSignificantDigits; diff --git a/apps/constant.h b/apps/constant.h index 8cf5ea017..b2e70ce9a 100644 --- a/apps/constant.h +++ b/apps/constant.h @@ -4,6 +4,7 @@ class Constant { public: constexpr static int LargeNumberOfSignificantDigits = 7; + constexpr static int MediumNumberOfSignificantDigits = 6; constexpr static int ShortNumberOfSignificantDigits = 4; }; diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 6477f404a..3b91c1000 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -44,7 +44,7 @@ void GraphController::reloadBannerView() { buffer[1] = '\''; TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); float y = f->approximateDerivative(m_cursor->x(), myApp->localContext()); - Complex::convertFloatToText(y, buffer + legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + Complex::convertFloatToText(y, buffer + legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); m_bannerView.setLegendAtIndex(buffer, 2); } diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index 2d9060a10..455587417 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -77,7 +77,7 @@ void GraphController::reloadBannerView() { strlcpy(buffer+numberOfChar, legend, legendLength+1); numberOfChar += legendLength; } else { - numberOfChar += Complex::convertFloatToText(roundf((float)*m_selectedDotIndex+1.0f), buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal); + numberOfChar += Complex::convertFloatToText(roundf((float)*m_selectedDotIndex+1.0f), buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal); } legend = ") "; legendLength = strlen(legend); @@ -97,7 +97,7 @@ void GraphController::reloadBannerView() { legendLength = strlen(legend); strlcpy(buffer, legend, legendLength+1); numberOfChar += legendLength; - numberOfChar += Complex::convertFloatToText(x, buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + numberOfChar += Complex::convertFloatToText(x, buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); legend = " "; legendLength = strlen(legend); strlcpy(buffer+numberOfChar, legend, legendLength+1); @@ -115,7 +115,7 @@ void GraphController::reloadBannerView() { legendLength = strlen(legend); strlcpy(buffer, legend, legendLength+1); numberOfChar += legendLength; - numberOfChar += Complex::convertFloatToText(y, buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + numberOfChar += Complex::convertFloatToText(y, buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); legend = " "; legendLength = strlen(legend); strlcpy(buffer+numberOfChar, legend, legendLength+1); diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index 00a0d3164..5ca07391a 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -116,7 +116,7 @@ void FunctionGraphController::reloadBannerView() { strlcpy(buffer, legend, legendLength+1); numberOfChar += legendLength; buffer[0] = functionStore()->symbol(); - numberOfChar += Complex::convertFloatToText(m_cursor->x(), buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + numberOfChar += Complex::convertFloatToText(m_cursor->x(), buffer+numberOfChar, Complex::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); legend = " "; legendLength = strlen(legend); strlcpy(buffer+numberOfChar, legend, legendLength+1); @@ -134,7 +134,7 @@ void FunctionGraphController::reloadBannerView() { assert(m_indexFunctionSelectedByCursor < functionStore()->numberOfActiveFunctions()); Function * f = functionStore()->activeFunctionAtIndex(m_indexFunctionSelectedByCursor); buffer[0] = f->name()[0]; - numberOfChar += Complex::convertFloatToText(m_cursor->y(), buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits); + numberOfChar += Complex::convertFloatToText(m_cursor->y(), buffer+legendLength, Complex::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); legend = " "; legendLength = strlen(legend); strlcpy(buffer+numberOfChar, legend, legendLength+1);