## Storage size from bits

March 29, 2016

Last week, we had a look at the computation of Log2 using templates and constexpr. Of course, I had ulterior motives. In particular, I was interested in allocating just the right number of bits for a field in a bit field, but rather than hard-coding it, having it deduced from a template argument. Let’s see how we can do that.

## Log2 (with C++ metaprogramming)

March 22, 2016

C++ meta-programming a powerful tool. Not only can you use it to build generic types (such as the STL’s std::list), you can also use it to have compile-time evaluation. Let’s have a look at a simple problem that can be solved in two very different ways: computing the Log base 2 of an integer.

## Sums of powers

March 15, 2016

When you’re studying algorithms, there is a number of series and expression that keep showing up. A while ago, I discussed the special form $\sum_{i=1}^n i a^i$. But that’s not the only one. Another form that keeps showing up is

$\displaystyle s_k(n)=\sum_{i=1}^n i^k$.

We can look the particular form this sum takes for specific $k$ in some compendium (like CRC’s tables and formulae, that have seen 30-something editions over the last half century), or… you can find the formula yourself. It’s a bit tedious, but not that complicated.

## Science!

March 8, 2016

Sorry, no entry for this week: I’ve been rather busy lately (because of science).

## Real dice.

March 1, 2016

Suppose you want to draw randomly a number between 0 and 1, with multiple throws of a six sided dice, what would you write down on its face?