mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/poincare] Use IEEE754::exponentBase10 instead of floor(log10)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user