0.1.1 Interval

This commit is contained in:
rob tillaart 2021-05-28 13:35:27 +02:00
parent 15aeb4751a
commit 7ec18f1fec
7 changed files with 32 additions and 18 deletions

View File

@ -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 --

View File

@ -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;

View File

@ -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:

View File

@ -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__);

View File

@ -15,7 +15,8 @@
"type": "git",
"url": "https://github.com/RobTillaart/Interval"
},
"version":"0.1.0",
"version": "0.1.1",
"license": "MIT",
"frameworks": "*",
"platforms": "*"
}

View File

@ -1,10 +1,10 @@
name=Interval
version=0.1.0
version=0.1.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for Interval datatype
paragraph=
category=data processing
category=Data Processing
url=https://github.com/RobTillaart/Interval.git
architectures=*
includes=Interval.h

View File

@ -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()
// --------