diff --git a/libraries/Interval/Interval.cpp b/libraries/Interval/Interval.cpp index 8629434b..b1b0e814 100644 --- a/libraries/Interval/Interval.cpp +++ b/libraries/Interval/Interval.cpp @@ -2,16 +2,18 @@ // FILE: Interval.cpp // AUTHOR: Rob Tillaart // DATE: 2020-07-21 -// VERSION: 0.1.0 +// VERSION: 0.1.1 // PURPOSE: Arduino library for Interval datatype // URL: https://github.com/RobTillaart/Interval // // 0.0.1 2020-07-20 initial version (not complete) // 0.1.0 2020-12-30 arduino-ci, unit tests, setRange() +// 0.1.1 2021-05-27 arduino-lint #include "Interval.h" + Interval::Interval(float lo, float hi) { if (lo <= hi) @@ -26,24 +28,28 @@ Interval::Interval(float lo, float hi) } }; + Interval::Interval(float f) { _lo = f; _hi = f; }; + Interval::Interval() { _lo = 0; _hi = 0; }; + float Interval::relAccuracy() { if (value() == 0.0) return -1; return abs(range() / value()); // TODO /2 ? } + void Interval::setRange(float r) { float f = value(); @@ -74,21 +80,25 @@ Interval Interval::operator + (const Interval &in) return Interval(_lo + in._lo, _hi + in._hi); } + Interval Interval::operator - (const Interval &in) { return Interval(_lo - in._hi, _hi - in._lo); } + Interval Interval::operator * (const Interval &in) { return Interval(_lo * in._lo, _hi * in._hi); } + Interval Interval::operator / (const Interval &in) { return Interval(_lo / in._hi, _hi / in._lo); } + Interval Interval::operator += (const Interval &in) { _lo += in._lo; @@ -96,6 +106,7 @@ Interval Interval::operator += (const Interval &in) return *this; } + Interval Interval::operator -= (const Interval &in) { _lo -= in._hi; @@ -103,6 +114,7 @@ Interval Interval::operator -= (const Interval &in) return *this; } + Interval Interval::operator *= (const Interval &in) { _lo *= in._lo; @@ -110,6 +122,7 @@ Interval Interval::operator *= (const Interval &in) return *this; } + Interval Interval::operator /= (const Interval &in) { _lo /= in._hi; @@ -128,6 +141,7 @@ bool Interval::operator == (const Interval &in) return ((_lo == in._lo) && (_hi == in._hi)); } + bool Interval::operator != (const Interval &in) { return ((_lo != in._lo) || (_hi != in._hi)); @@ -155,9 +169,5 @@ bool Interval::operator != (const Interval &in) // } - - - - // -- END OF FILE -- diff --git a/libraries/Interval/Interval.h b/libraries/Interval/Interval.h index b87ec47a..5f36cb9b 100644 --- a/libraries/Interval/Interval.h +++ b/libraries/Interval/Interval.h @@ -3,20 +3,22 @@ // FILE: Interval.h // AUTHOR: Rob Tillaart // DATE: 2020-07-21 -// VERSION: 0.1.0 +// VERSION: 0.1.1 // PURPOSE: Arduino library for Interval datatype // URL: https://github.com/RobTillaart/Interval // // HISTORY: // see Interval.cpp file + #include "Arduino.h" -#define INTERVAL_LIB_VERSION "0.1.0" +#define INTERVAL_LIB_VERSION (F("0.1.1")) + class Interval: public Printable { - public: +public: // CONSTRUCTOR Interval(); Interval(float lo, float hi); @@ -59,9 +61,7 @@ class Interval: public Printable // Interval operator ^ (const Interval&); // // smaller - - - private: +private: float _lo; float _hi; uint8_t _decimals = 3; diff --git a/libraries/Interval/README.md b/libraries/Interval/README.md index 013e3c9e..5662a5cb 100644 --- a/libraries/Interval/README.md +++ b/libraries/Interval/README.md @@ -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. - ## Interface 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 <= ** + ### Set operators **To be investigated** include: diff --git a/libraries/Interval/examples/interval_demo/interval_demo.ino b/libraries/Interval/examples/interval_demo/interval_demo.ino index 65d1bbe0..efbf8bcd 100644 --- a/libraries/Interval/examples/interval_demo/interval_demo.ino +++ b/libraries/Interval/examples/interval_demo/interval_demo.ino @@ -6,11 +6,13 @@ // DATE: 2020-07-21 // URL: https://github.com/RobTillaart/Interval + #include "Interval.h" Interval x(1, 2); Interval y(2, 3); + void setup() { Serial.begin(115200); @@ -23,10 +25,12 @@ void setup() Serial.println("\nDone..."); } + void loop() { } + void test_print() { Serial.println(__FUNCTION__); diff --git a/libraries/Interval/library.json b/libraries/Interval/library.json index 5602d19c..b4d84a6b 100644 --- a/libraries/Interval/library.json +++ b/libraries/Interval/library.json @@ -15,7 +15,8 @@ "type": "git", "url": "https://github.com/RobTillaart/Interval" }, - "version":"0.1.0", + "version": "0.1.1", + "license": "MIT", "frameworks": "*", "platforms": "*" } diff --git a/libraries/Interval/library.properties b/libraries/Interval/library.properties index 86c09ee7..5c44f09b 100644 --- a/libraries/Interval/library.properties +++ b/libraries/Interval/library.properties @@ -1,10 +1,10 @@ name=Interval -version=0.1.0 +version=0.1.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for Interval datatype paragraph= -category=data processing +category=Data Processing url=https://github.com/RobTillaart/Interval.git architectures=* includes=Interval.h diff --git a/libraries/Interval/test/unit_test_001.cpp b/libraries/Interval/test/unit_test_001.cpp index bd7594c6..4c5b1454 100644 --- a/libraries/Interval/test/unit_test_001.cpp +++ b/libraries/Interval/test/unit_test_001.cpp @@ -41,6 +41,7 @@ unittest_setup() { } + unittest_teardown() { } @@ -150,7 +151,6 @@ unittest(test_math_basic_2) } - unittest(test_comparisons) { fprintf(stderr, "VERSION: %s\n", INTERVAL_LIB_VERSION ); @@ -183,11 +183,10 @@ unittest(test_comparisons) // assertTrue(x >= x); // assertTrue(x >= a); // assertFalse(x >= y); - } - unittest_main() + // --------