Urgent.News

What's breaking now, across thousands of outlets.

Tech

Making all divisions slower to fix a bug in 0.000000000000000000542% of cases

For languages like Futhark, which define signed integer overflow as a legal operation, generating correct C code is tricky due to C's undefined behavior surrounding signed integer overflow. The source material explains that the most negative signed integer cannot be represented as a positive number in two's complement representation, leading to issues when attempting to divide by -1.

This results in signed integer overflow, a scenario that C handles as undefined behavior. Consequently, if the most negative signed integer is divided by -1, the correct result cannot be represented in signed integers, causing undefined behavior in C, and potentially triggering a CPU exception on x86 architectures. The Futhark compiler resolves this by generating signed C division, but this approach fails for the most negative number where the result would be out of range.

To address this, the Futhark runtime system introduces a workaround ensuring correct arithmetic even in edge cases, thereby avoiding undefined behavior and crashing programs.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at futhark-lang.org →

More in Tech

More from Monday 19 October →