News for hackers. Stuff that matters.
Re:The Little Bool of Doom (2025) by Joker_vD on Sunday February 08, 2026 @06:51PM (#46939845)
Yeah, but it's a shame that almost every language gets it wrong (and even traditional presentation of mathematical logic) and uses zero as representation of FALSE. It should represent TRUE!
Re:The Little Bool of Doom (2025) by rhplus on Sunday February 08, 2026 @09:40PM (#46940986)
Pedantic: the axioms of Boolean algebra don’t assign any natural numbers to the elements “top” and “bottom” of the set it operates on. The notation is usually “1” and “0” but it doesn’t have to be. It’s a convenience that many computer languages have named those elements “true” and “false”, and yes, it’s totally valid that in some representations, top = 0 = true and bottom = 1 = false.
Re:The Little Bool of Doom (2025) by pwdisswordfishy on Monday February 09, 2026 @01:55AM (#46942347)
Technically true, in practice using 0 for the bottom element and 1 for the top is a pretty strong convention; justified, for example, by the connection to probability measures and isomorphism with the Boolean ring ℤ/2ℤ.
Re:The Little Bool of Doom (2025) by jabl on Monday February 09, 2026 @05:29AM (#46943713)
If you want to make an argument for something else being the representations of boolean variables than 0 for false and 1 for true, one could make the case for true being all bits set.

That would make it slightly easier to do things like memset()'ing a vector of boolean, or a struct containing a boolean like in this case. Backwards compatibility with pre-_Bool boolean expressions in C99 probably made that a non starter in any case.

Re:The Little Bool of Doom (2025) by adrian_b on Monday February 09, 2026 @09:09AM (#46945371)
A 1-bit integer can be interpreted as either a signed integer or as an unsigned integer, exactly like an integer number of any other size.

Converting a 1-bit integer to a byte-sized or word-sized integer, by using the same extension rules as for any other size (i.e. by using either sign extension or zero extension), yields as the converted value for "true" either "1" for the unsigned integer interpretation or the value with all ones (i.e. "-1") for the signed integer interpretation.

So you could have "unsigned bool" and "signed bool", exactly like you have "unsigned char" and "signed char", to choose between the 2 possible representations.

Re:The Little Bool of Doom (2025) by alberto-m on Monday February 09, 2026 @11:45AM (#46947457)
> one could make the case for true being all bits set

Historical note: this was the case in QBasic, where true was defined as -1.

Re:The Little Bool of Doom (2025) by Joker_vD on Monday February 09, 2026 @01:56PM (#46949317)
There, apparently, were quite a number of ISAs where checking the sign bit was more convenient (performant?) than checking (in)equality with zero.
Re:The Little Bool of Doom (2025) by jabl on Monday February 09, 2026 @06:22PM (#46953041)
Some Fortran compilers also did this. MS Powerstation Fortran at least, IIRC.
Re:The Little Bool of Doom (2025) by direwolf20 on Monday February 09, 2026 @06:17AM (#46944016)
Including the words "top" and "bottom". In my language, if(x) is the same as if(x==bottom), and 1<2 resolves to bottom. Take that.
Re:The Little Bool of Doom (2025) by adrian_b on Monday February 09, 2026 @08:52AM (#46945203)
That is right, and you could map the Boolean values to other numbers, e.g. mapping them to +1 and -1 corresponds better to many of the hardware implementation techniques for logic circuits.

However when the use of Boolean algebra is embedded in some bigger theories, there are cases when the mapping to 0 and 1 becomes mandatory, e.g. in relationship with the theory of probabilities or with the theory of binary polynomials, where the logical operations can be mapped to arithmetic or algebraic operations.

The mapping to 0 and 1 is fully exploited in APL and its derivatives, where it enables the concise writing of many kinds of conditional expressions (in a similar manner to how mask registers are used in GPUs and in AVX-512).

Re:The Little Bool of Doom (2025) by Joker_vD on Monday February 09, 2026 @09:49AM (#46945815)
> Pedantic: the axioms of Boolean algebra don’t assign any natural numbers to the elements “top” and “bottom” of the set it operates on.

Yes? That's precisely what I meant when I said that the traditional presentation of mathematical logic get it wrong: it assigns 0 to FALSE and 1 to TRUE, but it can be done other way around.

Re:The Little Bool of Doom (2025) by userbinator on Sunday February 08, 2026 @10:05PM (#46941127)
Zero as the absence of something definitely makes more sense as false than true. It is the case for these common C idioms:

    while(p) {
        // do something with p
        ...
        p = p->next;
    }

    if(err=foo()) {
        printf("Error %d occurred\n", err);
        ...
    }