Numworks Epsilon  1.4.1
Graphing Calculator Operating System
discrete_calculation.cpp
Go to the documentation of this file.
1 #include "discrete_calculation.h"
2 #include <assert.h>
3 #include <ion.h>
4 #include <cmath>
5 
6 namespace Probability {
7 
9  Calculation(),
10  m_abscissa(0.0),
11  m_result(0.0)
12 {
13  compute(0);
14 }
15 
17  return Type::Discrete;
18 }
19 
21  return 2;
22 }
23 
25  return 1;
26 }
27 
29  assert(index >= 0 && index < 2);
30  if (index == 0) {
31  return I18n::Message::DiscreteLegend;
32  }
33  return I18n::Message::LeftIntegralSecondLegend;
34 }
35 
36 void DiscreteCalculation::setParameterAtIndex(double f, int index) {
37  assert(index == 0);
38  double rf = std::round(f);
39  m_abscissa = rf;
40  compute(index);
41 }
42 
43 
45  assert(index >= 0 && index < 2);
46  if (index == 0) {
47  return m_abscissa;
48  }
49  return m_result;
50 }
51 
53  return m_abscissa;
54 }
55 
57  return m_abscissa;
58 }
59 
60 void DiscreteCalculation::compute(int indexKnownElement) {
61  if (m_law == nullptr) {
62  return;
63  }
64  m_result = m_law->evaluateAtDiscreteAbscissa(m_abscissa);
65 }
66 
67 }
#define assert(e)
Definition: assert.h:9
double parameterAtIndex(int index) override
I18n::Message legendForParameterAtIndex(int index) override
#define round(x)
Definition: math.h:192
void setParameterAtIndex(double f, int index) override
virtual double evaluateAtDiscreteAbscissa(int k) const
Definition: law.cpp:134