News for hackers. Stuff that matters.
Re:Brent's Encapsulated C Programming Rules (2020) by syockit on Tuesday December 09, 2025 @11:37AM (#46207013)
Check against FLT_EPSILON. Oh boy.

The reason is floating point precision errors, sure, but that check is not going to solve the problems.

Took a difference of two numbers with large exponents, where the result should be algebraically zero but isn't quite numerically? Then this check fails to catch it. Took another difference of two numbers with very small exponents, where the result is not actually algebraically zero? This check says it's zero.

Re:Brent's Encapsulated C Programming Rules (2020) by syncsynchalt on Tuesday December 09, 2025 @01:04PM (#46208245)
Yeah, at the least you'll need an understanding of ULPs[0] before you can write code that's safe in this way. And understanding ULPs means understanding that no single constant is going to be applicable across the FLT or DBL range.

[0] https://en.wikipedia.org/wiki/Unit_in_the_last_place