# Float and integer arithmetic follow two different paradigms

DevFeed: [Float and integer arithmetic follow two different paradigms](<https://devfeed.tech/articles/float-and-integer-arithmetic-follow-two-different-paradigms-64618.md>)

Original publisher: [Read original article](<http://blog.pkh.me/p/49-float-and-integer-arithmetic-follow-two-different-paradigms.html>)

Published: 2026-10-04T16:16:40Z

Content type: article

Language: en

Sources: [Last Static](<https://devfeed.tech/sources/the-last-static-blog-rss.md>)

Topics: [floating-point](<https://devfeed.tech/topics/floating-point.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>)

Tags: [crash](<https://devfeed.tech/tags/crash.md>), [floating-point](<https://devfeed.tech/tags/floating-point.md>), [infinite](<https://devfeed.tech/tags/infinite.md>), [math](<https://devfeed.tech/tags/math.md>), [max](<https://devfeed.tech/tags/max.md>), [prevent](<https://devfeed.tech/tags/prevent.md>), [prog](<https://devfeed.tech/tags/prog.md>), [runtime](<https://devfeed.tech/tags/runtime.md>), [rust](<https://devfeed.tech/tags/rust.md>), [undefined-behavior](<https://devfeed.tech/tags/undefined-behavior.md>)

## AI overview

The article explains why floating-point and integer arithmetic require different error-handling approaches. It recommends checking whether floating-point results are finite instead of relying on arbitrary epsilon thresholds, while cautioning that finite results can still be numerically inaccurate. It also discusses limitations in GLSL and contrasts float handling with checked integer operations in C and Rust.

## Source excerpt

When working with floats, we tend to reuse the more familiar integer arithmetic patterns. More specifically, we always try to prevent a disaster rather than reacting to it. I keep noticing this pattern over and over again, and seeing that LLMs still get it wrong most of the time means that, either I am wrong, or everyone else is; it's obviously the latter, and I'm going to explain why. Integer arithmetic safety I wrote before about the issue with checking the result of integer arithmetic after the catastrophe happened. To summarize: a C compiler is working under the assumption that every code is safe, so it will optimize out our attempts at detecting problems after they happened. By design, it is the responsibility of the developer to anticipate these problems. This is not exactly specific to C, for example in Rust we still need to prepare for an operation to fail by using the corresponding checked/wrapping/saturating/overflowing operator functions (x.checked_div(y), x.saturating_add(y), etc). Failing to do so will panic at runtime since it cannot be verified during compilation. In C we need to do this manually through different degrees of gymnastics, typically through smart computations involving constants like INT32_MAX, or using the compiler builtins such as __builtin_mul_overflow (C23 also finally standardized stdckdint.h with ckd_* function helpers). Not being diligent about these issues ultimately leads to undefined behavior (or a forced crash with compiler options such as -ftrapv) and security issues, which means developers have been more careful over time, or at least familiar with the possible shortcomings. Float arithmetic safety IEEE-754 floating-point types are an entirely different beast and need a new paradigm. Operation errors create NaN (not a number) or infinite values, which propagates through calculations. They do not crash the program, and they're perfectly legitimate. Still, our habits push us to prepare for the worse, so we often see dysfunctio