A boolean of 3 states is the one that has the false, the true and the undefined. So in Java there is a natural that is the Boolean
, not to be confused with boolean
(What difference between Boolean and Boolean?). The first accepts a null
, then there is a third state.
In C# you can use a bool?
. There’s language that only has three-state boolean, and a lot of people don’t even realize it.
In languages that don’t have it, you’d have to create a convention or even an enumeration if it exists in the language, something like that:
enum tribool { false, true, maybe = -1 }
Some people say it shouldn’t be used, and if you have three states then it’s not a boolean, it’s something else. In fact this date thing seems to me to be something else. Something like this:
enum compara { igual, depois, antes = -1 }
I put in the Github for future reference.
Is there a name for the "3-phase Boolean"?
Apparently it is called trivalent or ternary logic (after all the boolean is the binary), according to Wikipedia (in more complete English). Other terms can be used as seen in the comments. There does not seem to be a universal name. And since its use is not so much encouraged, it might be better that way.
From what I understand no one received credit for the "invention" and so no one was honored. The binary might not call it boolean if you didn’t give George Boole so much credit.
I’ve never seen this term, would it be 3 states? Can you cite an example of usage with comparison of dates.
– Maniero
Three-valued logic?
– rray
@Maniero if understood well, the idea is the same applied in the function
strcmp
C, which has the 3 possible returns; or the one used by Spaceship Operator in PHP.– Woss
@rray sounds good, but then in fact it doesn’t have a name? since you are inquiring.
– Guilherme Lautert
Have you ever heard this term in a database, in case a column may have some value, nothing and null (unknown).
– rray
@Andersoncarloswoss yes, but there is nothing boolean of 3 states (or stages) there.
– Maniero
Yes, it is up to @Guilhermelautert to say what he asked. In my view, the term "3-state boolean" was used in a misleading way, even unintentionally, which possibly sidetracked the question. Or got it wrong :D
– Woss
My colleague found the following in wiki which I think is very interesting. ""
– Guilherme Lautert