GithubHelp home page GithubHelp logo

robtillaart / troolean Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 37 KB

Arduino Library for a three state logic datatype supporting {True False Unknown}

License: MIT License

C++ 100.00%
arduino tristate boolean

troolean's Introduction

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

Troolean

Arduino Library for a three state logic data type supporting {True False Unknown}.

Description

Troolean is a data type that implements three state logic with the values {True False Unknown }

Logic operators are similar to boolean and behave the same for the familiar boolean values.

Trooleans can be used e.g. to indicate a value is valid, invalid or unknown to be valid or not. Imagine a monitoring application which has different sensors e.g. temperature. If the sensor is sampled less than 1 minute ago one could say the value is valid. If the last sample is taken more than an hour ago it could have changed (a lot) or not. So one does not know if the temperature has become invalid or not. Boolean logic would make it invalid, but troolean allows to state we just don't know. As long as there is no urgency (need a valid value) one does not need to resample yet.

See also https://en.wikipedia.org/wiki/Three-valued_logic

Interface

#include "Troolean.h"

Constructor

  • Troolean() value is unknown.
  • Troolean(const int8_t) 0 = false, -1 = unknown anything else = true
  • Troolean(const Troolean&) copy constructor.

Equality operators

  • bool operator == equals
  • bool operator != not equal
  • operator bool() convert to boolean.

Logical operators

  • **Troolean operator ! ** negation, not UNKNOWN == UNKNOWN.
  • **Troolean operator && ** AND
  • **Troolean operator || ** OR

Value operators

  • bool isTrue() if not false and if not unknown.
  • bool isFalse() idem.
  • bool isUnknown() idem.

Operation

See examples

Future

Must

  • fix isTrue() to allow internal values to be anything except 0 and -1 (0.2.0)
  • check logical operators.
  • update documentation

Should

  • add unit tests (derive from test troolean.ino?)
  • add examples

Could

  • Troolean operator &&=
  • Troolean operator ||=
  • bool toBool(); // returns random true/false if unknown....

Wont

  • extend with don't care ? ==> four state logic ? Foolean?
    • => new class.

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,

troolean's People

Contributors

robtillaart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

troolean's Issues

fix isTrue()

  • fix isTrue() to allow internal values to be anything except 0 and -1 (0.2.0)
  • check other logic too

Need a don't care value too ?

In some situations the value of a variable is known but not relevant, so a don't care value could be a missing state. However the value might at the same time be true or false.

This means troolean can be seen as a boolean with meta information:

bool state don't care validity ...
true yes known
false no unknown

Needs investigation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.