mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.1 Interval
This commit is contained in:
parent
15aeb4751a
commit
7ec18f1fec
@ -2,16 +2,18 @@
|
|||||||
// FILE: Interval.cpp
|
// FILE: Interval.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// DATE: 2020-07-21
|
// DATE: 2020-07-21
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// PURPOSE: Arduino library for Interval datatype
|
// PURPOSE: Arduino library for Interval datatype
|
||||||
// URL: https://github.com/RobTillaart/Interval
|
// URL: https://github.com/RobTillaart/Interval
|
||||||
//
|
//
|
||||||
// 0.0.1 2020-07-20 initial version (not complete)
|
// 0.0.1 2020-07-20 initial version (not complete)
|
||||||
// 0.1.0 2020-12-30 arduino-ci, unit tests, setRange()
|
// 0.1.0 2020-12-30 arduino-ci, unit tests, setRange()
|
||||||
|
// 0.1.1 2021-05-27 arduino-lint
|
||||||
|
|
||||||
|
|
||||||
#include "Interval.h"
|
#include "Interval.h"
|
||||||
|
|
||||||
|
|
||||||
Interval::Interval(float lo, float hi)
|
Interval::Interval(float lo, float hi)
|
||||||
{
|
{
|
||||||
if (lo <= hi)
|
if (lo <= hi)
|
||||||
@ -26,24 +28,28 @@ Interval::Interval(float lo, float hi)
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Interval::Interval(float f)
|
Interval::Interval(float f)
|
||||||
{
|
{
|
||||||
_lo = f;
|
_lo = f;
|
||||||
_hi = f;
|
_hi = f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Interval::Interval()
|
Interval::Interval()
|
||||||
{
|
{
|
||||||
_lo = 0;
|
_lo = 0;
|
||||||
_hi = 0;
|
_hi = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
float Interval::relAccuracy()
|
float Interval::relAccuracy()
|
||||||
{
|
{
|
||||||
if (value() == 0.0) return -1;
|
if (value() == 0.0) return -1;
|
||||||
return abs(range() / value()); // TODO /2 ?
|
return abs(range() / value()); // TODO /2 ?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Interval::setRange(float r)
|
void Interval::setRange(float r)
|
||||||
{
|
{
|
||||||
float f = value();
|
float f = value();
|
||||||
@ -74,21 +80,25 @@ Interval Interval::operator + (const Interval &in)
|
|||||||
return Interval(_lo + in._lo, _hi + in._hi);
|
return Interval(_lo + in._lo, _hi + in._hi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Interval Interval::operator - (const Interval &in)
|
Interval Interval::operator - (const Interval &in)
|
||||||
{
|
{
|
||||||
return Interval(_lo - in._hi, _hi - in._lo);
|
return Interval(_lo - in._hi, _hi - in._lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Interval Interval::operator * (const Interval &in)
|
Interval Interval::operator * (const Interval &in)
|
||||||
{
|
{
|
||||||
return Interval(_lo * in._lo, _hi * in._hi);
|
return Interval(_lo * in._lo, _hi * in._hi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Interval Interval::operator / (const Interval &in)
|
Interval Interval::operator / (const Interval &in)
|
||||||
{
|
{
|
||||||
return Interval(_lo / in._hi, _hi / in._lo);
|
return Interval(_lo / in._hi, _hi / in._lo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Interval Interval::operator += (const Interval &in)
|
Interval Interval::operator += (const Interval &in)
|
||||||
{
|
{
|
||||||
_lo += in._lo;
|
_lo += in._lo;
|
||||||
@ -96,6 +106,7 @@ Interval Interval::operator += (const Interval &in)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Interval Interval::operator -= (const Interval &in)
|
Interval Interval::operator -= (const Interval &in)
|
||||||
{
|
{
|
||||||
_lo -= in._hi;
|
_lo -= in._hi;
|
||||||
@ -103,6 +114,7 @@ Interval Interval::operator -= (const Interval &in)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Interval Interval::operator *= (const Interval &in)
|
Interval Interval::operator *= (const Interval &in)
|
||||||
{
|
{
|
||||||
_lo *= in._lo;
|
_lo *= in._lo;
|
||||||
@ -110,6 +122,7 @@ Interval Interval::operator *= (const Interval &in)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Interval Interval::operator /= (const Interval &in)
|
Interval Interval::operator /= (const Interval &in)
|
||||||
{
|
{
|
||||||
_lo /= in._hi;
|
_lo /= in._hi;
|
||||||
@ -128,6 +141,7 @@ bool Interval::operator == (const Interval &in)
|
|||||||
return ((_lo == in._lo) && (_hi == in._hi));
|
return ((_lo == in._lo) && (_hi == in._hi));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Interval::operator != (const Interval &in)
|
bool Interval::operator != (const Interval &in)
|
||||||
{
|
{
|
||||||
return ((_lo != in._lo) || (_hi != in._hi));
|
return ((_lo != in._lo) || (_hi != in._hi));
|
||||||
@ -155,9 +169,5 @@ bool Interval::operator != (const Interval &in)
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
@ -3,20 +3,22 @@
|
|||||||
// FILE: Interval.h
|
// FILE: Interval.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// DATE: 2020-07-21
|
// DATE: 2020-07-21
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// PURPOSE: Arduino library for Interval datatype
|
// PURPOSE: Arduino library for Interval datatype
|
||||||
// URL: https://github.com/RobTillaart/Interval
|
// URL: https://github.com/RobTillaart/Interval
|
||||||
//
|
//
|
||||||
// HISTORY:
|
// HISTORY:
|
||||||
// see Interval.cpp file
|
// see Interval.cpp file
|
||||||
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define INTERVAL_LIB_VERSION "0.1.0"
|
#define INTERVAL_LIB_VERSION (F("0.1.1"))
|
||||||
|
|
||||||
|
|
||||||
class Interval: public Printable
|
class Interval: public Printable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// CONSTRUCTOR
|
// CONSTRUCTOR
|
||||||
Interval();
|
Interval();
|
||||||
Interval(float lo, float hi);
|
Interval(float lo, float hi);
|
||||||
@ -59,9 +61,7 @@ class Interval: public Printable
|
|||||||
// Interval operator ^ (const Interval&); //
|
// Interval operator ^ (const Interval&); //
|
||||||
// smaller
|
// smaller
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
private:
|
|
||||||
float _lo;
|
float _lo;
|
||||||
float _hi;
|
float _hi;
|
||||||
uint8_t _decimals = 3;
|
uint8_t _decimals = 3;
|
||||||
|
@ -23,7 +23,6 @@ It was inspired by the frink language which has an interval datatype.
|
|||||||
Frink itself is not investigated, so semantics are not necessary similar.
|
Frink itself is not investigated, so semantics are not necessary similar.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
|
|
||||||
The Interval class implements the public interface of Printable.
|
The Interval class implements the public interface of Printable.
|
||||||
@ -107,6 +106,7 @@ The Probably group will be more like fuzzy logic so a float between 0..100%.
|
|||||||
- **bool < **
|
- **bool < **
|
||||||
- **bool <= **
|
- **bool <= **
|
||||||
|
|
||||||
|
|
||||||
### Set operators
|
### Set operators
|
||||||
|
|
||||||
**To be investigated** include:
|
**To be investigated** include:
|
||||||
|
@ -6,11 +6,13 @@
|
|||||||
// DATE: 2020-07-21
|
// DATE: 2020-07-21
|
||||||
// URL: https://github.com/RobTillaart/Interval
|
// URL: https://github.com/RobTillaart/Interval
|
||||||
|
|
||||||
|
|
||||||
#include "Interval.h"
|
#include "Interval.h"
|
||||||
|
|
||||||
Interval x(1, 2);
|
Interval x(1, 2);
|
||||||
Interval y(2, 3);
|
Interval y(2, 3);
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
@ -23,10 +25,12 @@ void setup()
|
|||||||
Serial.println("\nDone...");
|
Serial.println("\nDone...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void test_print()
|
void test_print()
|
||||||
{
|
{
|
||||||
Serial.println(__FUNCTION__);
|
Serial.println(__FUNCTION__);
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/Interval"
|
"url": "https://github.com/RobTillaart/Interval"
|
||||||
},
|
},
|
||||||
"version":"0.1.0",
|
"version": "0.1.1",
|
||||||
|
"license": "MIT",
|
||||||
"frameworks": "*",
|
"frameworks": "*",
|
||||||
"platforms": "*"
|
"platforms": "*"
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
name=Interval
|
name=Interval
|
||||||
version=0.1.0
|
version=0.1.1
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=Arduino library for Interval datatype
|
sentence=Arduino library for Interval datatype
|
||||||
paragraph=
|
paragraph=
|
||||||
category=data processing
|
category=Data Processing
|
||||||
url=https://github.com/RobTillaart/Interval.git
|
url=https://github.com/RobTillaart/Interval.git
|
||||||
architectures=*
|
architectures=*
|
||||||
includes=Interval.h
|
includes=Interval.h
|
||||||
|
@ -41,6 +41,7 @@ unittest_setup()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unittest_teardown()
|
unittest_teardown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -150,7 +151,6 @@ unittest(test_math_basic_2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unittest(test_comparisons)
|
unittest(test_comparisons)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "VERSION: %s\n", INTERVAL_LIB_VERSION );
|
fprintf(stderr, "VERSION: %s\n", INTERVAL_LIB_VERSION );
|
||||||
@ -183,11 +183,10 @@ unittest(test_comparisons)
|
|||||||
// assertTrue(x >= x);
|
// assertTrue(x >= x);
|
||||||
// assertTrue(x >= a);
|
// assertTrue(x >= a);
|
||||||
// assertFalse(x >= y);
|
// assertFalse(x >= y);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unittest_main()
|
unittest_main()
|
||||||
|
|
||||||
|
|
||||||
// --------
|
// --------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user