Articles contenant le tag integer arithmetic

Mid-point and linear interpolation done right

How many times did we write code like: Although this code is correct, it may suffer from overflows. The typical way to avoid those is to cast to a wider type. But how can you do this when the start and stop values are already using the largest integer type (eg. int64_t) ? The C++ […]

,

Pas de commentaire

Overflow-safe integer mul&div

When you do a multiply & divide operation, to ensure you don’t loose precision, you would start by the multiplication before the division. But in that case, it could be that the result of the multiplication overflows. The natural solution would go to use an intermediate storage of larger size. This uses concepts (C++20). For […]

, ,

Pas de commentaire