Numworks Epsilon  1.4.1
Graphing Calculator Operating System
curve_view_range.cpp
Go to the documentation of this file.
1 #include "curve_view_range.h"
2 #include <cmath>
3 #include <ion.h>
4 #include <assert.h>
5 #include <stddef.h>
6 #include <float.h>
7 
8 namespace Shared {
9 
11  float data[4] = {xMin(), xMax(), yMin(), yMax()};
12  size_t dataLengthInBytes = 4*sizeof(float);
13  assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4
14  return Ion::crc32((uint32_t *)data, dataLengthInBytes/sizeof(uint32_t));
15 }
16 
18  return 0.0f;
19 }
20 
21 float CurveViewRange::computeGridUnit(Axis axis, float min, float max) {
22  int a = 0;
23  int b = 0;
24  float d = max - min;
25  float maxNumberOfUnits = k_maxNumberOfXGridUnits;
26  float minNumberOfUnits = k_minNumberOfXGridUnits;
27  if (axis == Axis::Y) {
28  maxNumberOfUnits = k_maxNumberOfYGridUnits;
29  minNumberOfUnits = k_minNumberOfYGridUnits;
30  }
31  float units[3] = {k_smallGridUnitMantissa, k_mediumGridUnitMantissa, k_largeGridUnitMantissa};
32  for (int k = 0; k < 3; k++) {
33  float unit = units[k];
34  if (std::floor(std::log10(d/(unit*maxNumberOfUnits))) != std::floor(std::log10(d/(unit*minNumberOfUnits)))) {
35  b = std::floor(std::log10(d/(unit*minNumberOfUnits)));
36  a = unit;
37  }
38  }
39  return a*std::pow(10.0f,b);
40 }
41 
42 }
#define assert(e)
Definition: assert.h:9
def data
Definition: i18n.py:176
virtual float xMax()=0
static constexpr float k_maxNumberOfYGridUnits
unsigned int uint32_t
Definition: stdint.h:6
#define pow(x, y)
Definition: math.h:190
#define log10(x)
Definition: math.h:186
virtual float yMin()=0
virtual uint32_t rangeChecksum()
virtual float yMax()=0
float computeGridUnit(Axis axis, float min, float max)
uint32_t crc32(const uint32_t *data, size_t length)
Definition: device.cpp:37
static constexpr float k_maxNumberOfXGridUnits
#define floor(x)
Definition: math.h:179
virtual float xMin()=0