Function poisoning in C and C++

This article appeared was published as a guest post on fluent cpp. What does it mean to poison a function? The gcc compiler has an interesting pragma that I’ve rediscovered after four years since I’ve noticed it the first time: #pragma GCC poison. It works as follow: If there is an identifier that you want to prohibit in your source code, you can "poison" it, in order to get a compile error if that identifier appears in your codebase.

Read more →

Stop using regex for validation

Using regex for validation might cause more harm than good.

Read more →

Floating in C++ - part 7 - Runge-Kutta

The introduction to this article series can be found here, whereas here you can find all posts. In the last article I mentioned how there are many algorithms for solving ODE’s, but showed only the implementation for explicit and implicit Euler. The reason behind my decision was that those algorithms, and many others as well, are part of a larger family of algorithm: The Runge-Kutta methods. Again, Wikipedia does a great job by describing how to put up such a system.

Read more →

The introduction to this article series can be found here, whereas here you can find all posts. Ordinary differential equations and Partial differential equations are two big chapters in every numerical course, so I had to spend some time on those, particularly on ODE, since there are a lot of nice and simple algorithms to implement. Euler method The euler method is a very simple numerical procedure for approximating the solution of a ordinary differential equation (ODE) with a given initial value.

Read more →

Floating in C++ - part 5 - Linear algebra

The introduction to this article series can be found here, whereas here you can find all posts. MATLAB stands for MATrix LABoratory. This program and Octave define almost all operations through arrays and matrices. The reasoning behind such a decision is that for solving most complex problems, we will simplify them into a linear system, and solve the approximated problem. Having a good and efficient matrix system means to be able to write efficient mathematical code.

Read more →

Floating in C++ - part 4 - Testing

The introduction to this article series can be found here, whereas here you can find all posts. As I’ve written, for most functions, I’ve tried to ensure that the implementation is correct through multiple tests. Unfortunately, testing with floating point can be tricky. First of all, because of rounding issues, most of the time it is not possible to compare float values directly. There are some cases where it makes sense to compare values directly, but most of the time, we have to remember that we want to know is if a value is approximately equal to another.

Read more →