-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterval.h
69 lines (54 loc) · 1.81 KB
/
Interval.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
//
// FILE: Interval.h
// AUTHOR: Rob Tillaart
// DATE: 2020-07-21
// VERSION: 0.1.4
// PURPOSE: Arduino library for Interval datatype
// URL: https://github.com/RobTillaart/Interval
#include "Arduino.h"
#define INTERVAL_LIB_VERSION (F("0.1.4"))
class Interval: public Printable
{
public:
// CONSTRUCTOR
Interval();
Interval(float lo, float hi);
Interval(float f); // default zero interval [f, f]
// PRINTABLE
size_t printTo(Print& p) const;
void setDecimals(uint8_t n) { _decimals = n; };
// BASE FUNCTIONS
float value() { return (_hi /2 + _lo /2); }; // assumption / estimation
float range() { return _hi -_lo; };
float high() { return _hi; };
float low() { return _lo; };
float relAccuracy();
void setRange(float r);
// MATH OPERATORS
Interval operator + (const Interval&);
Interval operator - (const Interval&);
Interval operator * (const Interval&);
Interval operator / (const Interval&);
Interval operator += (const Interval&);
Interval operator -= (const Interval&);
Interval operator *= (const Interval&);
Interval operator /= (const Interval&);
// COMPARISON OPERATORS - compares value()
bool operator == (const Interval&);
bool operator != (const Interval&);
// bool operator > (const Interval&);
// bool operator >= (const Interval&);
// bool operator < (const Interval&);
// bool operator <= (const Interval&);
// SET OPERATORS
// Interval operator & (const Interval&); // common part [1, 5] & [4, 8] => [4, 5]
// Interval operator | (const Interval&); // superset [1, 5] | [4, 8] => [1, 8]
// Interval operator ^ (const Interval&); //
// smaller
private:
float _lo;
float _hi;
uint8_t _decimals = 3;
};
// -- END OF FILE --