Whatever sums your floats

January 24, 2017

While flipping the pages of a “Win this interview” book—just being curious, not looking for a new job—I saw this seemingly simple question: how would you compute the sum of a series of floats contained in a array? The book proceeded with the simple, obvious answer. But… is it that obvious?

Read the rest of this entry »


Size(_t) matters!

December 27, 2016

Sometime last week, a tweet from @nixCraft prompted the question, quite ironically, how do you get the maximum (largest positive) value for an integer?

max_int

Read the rest of this entry »


A Bit About Bit-Fields

January 5, 2016

Let’s make a detour through low-level programming this week. Let’s talk about bit-fields and some of their quirks.

amonite

Read the rest of this entry »


Enumerating 32 bits Floats

November 5, 2013

This week, let’s go back to (low level) programming, with IEEE floats. To unit test a function of float, it does not sound unreasonable to just enumerate them all. But how do we do that efficiently? Clearly f++ will not get us there.

Buoys_1

Nor will the machine-epsilon (the std::numeric_limits::epsilon()) because this value works fine around 1, but as the value diverges from 1, the epsilon basically becomes useless. We would either need a magnitude-dependent epsilon (which the standard library does not provide) or a way of enumerating explicitly the floats in increasing or decreasing order (something also not provided by the standard library). Well, let’s see how we can do that

Read the rest of this entry »


Two Features I’d Like to See in C and C++

October 1, 2013

This week, let’s discuss two features I’d really like to see in C and
C++; one trivial, one not so trivial.

fish-on-stilts

Read the rest of this entry »


Shallow Constitude

March 19, 2013

In programming languages, there are constructs that are of little pragmatic importance (that is, they do not really affect how code behaves or what code is generated by the compiler) but are of great “social” importance as they instruct the programmer as to what contract the code complies to.

200px-Padlock-light-silver.svg

One of those constructs in C++ is the const (and other access modifiers) that explicitly states to the programmer that this function argument will be treated as read-only, and that it’s safe to pass your data to it, it won’t be modified. But is it all but security theater?

Read the rest of this entry »


Compressed Series (Part II)

March 12, 2013

Last week we looked at an alternative series to compute e, and this week we will have a look at the computation of e^x. The usual series we learn in calculus textbook is given by

\displaystyle e^x=\sum_{n=0}^\infty \frac{x^n}{n!}

We can factorize the expression as

Read the rest of this entry »