your c is not standard c

29 points by nytpu a day ago on lobsters | 3 comments

interlandi | a day ago

CX_LIMITED_RANGE is a nightmare source of heisenbugs.

Once when I was working on an embedded project, I had a complex loop variant whos modulus exploded to infinity at night on Tuesdays, causing a fantastic infinite loop that only existed in -O2, with emulation on. The worst part was that the system would still work, interrupts still happened, and the watchdog would do its job, so the only observable behavior was that sometimes the battery life would be awful and I only knew to look at the logs because the MCU was way too hot.

riking | 15 hours ago

CX_LIMITED_RANGE

what the actual heck is the "obvious symbolic definition" of a division. Ow.

The C standard says:

The CX_LIMITED_RANGE pragma can be used to inform the implementation that (where the state is “on”) the usual mathematical formulas are acceptable. (footnote) The purpose of the pragma is to allow the implementation to use the formulas:

(x + iy) × (u + iv) = (xu − yv) + i(yu + xv)
(x + iy) / (u + iv) = [(xu + yv) + i(yu − xv)]/(u2 + v2)
| x + iy | = sqrt(x*x + y*y)

where the programmer can determine they are safe.