[apps/poincare] Use IEEE754::exponentBase10 instead of floor(log10)

This commit is contained in:
Léa Saviot
2020-02-10 15:28:41 +01:00
parent c9f83f6e7e
commit 6f4a51a56d
3 changed files with 7 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
#include "curve_view.h"
#include <cmath>
#include <ion.h>
#include <poincare/ieee754.h>
#include <assert.h>
#include <stddef.h>
#include <float.h>
@@ -22,8 +23,8 @@ float CurveViewRange::computeGridUnit(float minNumberOfUnits, float maxNumberOfU
float units[unitsCount] = {k_smallGridUnitMantissa, k_mediumGridUnitMantissa, k_largeGridUnitMantissa};
for (int k = 0; k < unitsCount; k++) {
float currentA = units[k];
int b1 = std::floor(std::log10(range/(currentA*maxNumberOfUnits)));
int b2 = std::floor(std::log10(range/(currentA*minNumberOfUnits)));
int b1 = Poincare::IEEE754<float>::exponentBase10(range/(currentA*maxNumberOfUnits));
int b2 = Poincare::IEEE754<float>::exponentBase10(range/(currentA*minNumberOfUnits));
if (b1 != b2) {
b = b2;
a = currentA;

View File

@@ -2,6 +2,7 @@
#include "../shared/poincare_helpers.h"
#include "../shared/text_helpers.h"
#include "app.h"
#include <poincare/ieee754.h>
#include <poincare/preferences.h>
#include <cmath>
#include <assert.h>
@@ -253,7 +254,7 @@ void HistogramController::initBarParameters() {
} else {
// Truncate the bar width, as we convert from float to double
const double precision = 7; // TODO factorize? This is an experimental value, the same as in Expression;;Epsilon<float>()
const double logBarWidth = std::floor(std::log10(barWidth));
const double logBarWidth = IEEE754<double>::exponentBase10(barWidth);
barWidth = ((int)(barWidth * std::pow(10.0, precision - logBarWidth))) * std::pow(10.0, -precision + logBarWidth);
}
m_store->setBarWidth(barWidth);

View File

@@ -1,6 +1,7 @@
#include <poincare/unit.h>
#include <poincare/division.h>
#include <poincare/float.h>
#include <poincare/ieee754.h>
#include <poincare/multiplication.h>
#include <poincare/power.h>
#include <poincare/rational.h>
@@ -61,7 +62,7 @@ const UnitNode::Prefix * UnitNode::Representative::bestPrefixForValue(double & v
/* Find the 'Prefix' with the most adequate 'exponent' for the order of
* magnitude of 'value'.
*/
const int orderOfMagnitude = std::floor(std::log10(std::fabs(value)));
const int orderOfMagnitude = IEEE754<double>::exponentBase10(std::fabs(value));
for (const Prefix * pre = m_outputPrefixes; pre < m_outputPrefixesUpperBound; pre++) {
unsigned int newDiff = absInt(orderOfMagnitude - pre->exponent() * exponent);
if (newDiff < diff) {