Yes? No? Maybe? (Part II)

March 27, 2018

Last week, we had a look at how to implement a trool, or a tri-valued boolean what accepts true, false, and undefined. We remarked that the storage of an enum likely defaults to int, and that my poc wouldn’t play well with std::vector as that container has no specialization to deal with this new type.

A specialization would be interesting because we can do much better than using an integer to store three different values. We can do much, much better.

Read the rest of this entry »


Yes? No? Maybe? (Part I)

March 20, 2018

Initializing arrays, or any variable for that matter, is always kind of a problem. Most of the times, you can get away with a default value, typically zero in C#C++, but not always. For floats, for example, NaN makes much more sense. Indeed, it’s initialized to not a number: it clearly states that it is initialized, consciously, to not a value. That’s neat. What about integers? Clearly, there’s no way to encode a NaI (not an integer), maybe std::numeric_limits::min(), which is still better than zero. What about bools?

Bool is trickier. In C++, bool is either false or true, and weak typing makes everything not zero true. However, if you assign 3 to a bool, it will be “normalized” to true, that is, exactly 1. Therefore, and not that surprisingly, you can’t have true, false, and maybe. Well, let’s fix that.

Read the rest of this entry »


Paeth’s Method (Square Roots, Part VII)

March 13, 2018

In Graphics Gems [1], Paeth proposes a fast (but quite approximate) method for the rapid computation of hypotenuse,

\displaystyle h=\sqrt{x^2+y^2}.

The goal here is to get rid of the big bad \sqrt{} because it is deemed “too expensive”—I wonder if that’s still actually true. First, he transforms the above equation:

Read the rest of this entry »


Encoding seeds

March 6, 2018

I was discussing procedural generation with one of my students when he brought up The Binding of Isaac, that delightfully quirky and creepy rogue-like game. One of the interesting features of the game is that the dungeons are randomly generated and that you can get the seeds for the dungeons and share them. A typical seed looks something like this:

QNFQ 8H7Z

So what does it encode?

Read the rest of this entry »