This commit is contained in:
Miloslav Ciz 2023-07-29 11:26:00 +02:00
parent e105277181
commit 89693a5451
13 changed files with 49 additions and 15 deletions

View file

@ -8,7 +8,9 @@ And there is more: floating point behavior really depends on the language you're
{ Really as I'm now getting down the float rabbit hole I'm seeing what a huge mess it all is, I'm not nearly an expert on this so maybe I've written some BS here, which just confirms how messy floats are. Anyway, from the articles I'm reading even being an expert on this issue doesn't seem to guarantee a complete understanding of it :) Just avoid floats if you can. ~drummyfish }
Is floating point literal evil? Well, of course not, but it is extremely overused. You may need it for precise scientific simulations, e.g. [numerical integration](numerical_integration.md), but as our [small3dlib](small3dlib.md) shows, you can comfortably do even [3D rendering](3d_rendering.md) without it. So always consider whether you REALLY need float. You mostly do not.
Is floating point literal evil? Well, of course not, but it is extremely overused. You may need it for precise scientific simulations, e.g. [numerical integration](numerical_integration.md), but as our [small3dlib](small3dlib.md) shows, you can comfortably do even [3D rendering](3d_rendering.md) without it. So always consider whether you REALLY need float. **You mostly do NOT need it**.
**Simple example of avoiding floating point**: many noobs think that if they e.g. need to multiply some integer *x* by let's say 2.34 they have to use floating point. This is of course false and just proves most retarddevs don't know elementary school [math](math.md). Multiplying *x* by 2.34 is the same as *(x * 234) / 100*, which we can [optimize](optimization.md) to an approximately equal division by power of two as *(x * 2396) / 1024*. Indeed, given e.g. *x = 56* we get the same integer result 131 in both cases, the latter just completely avoiding floating point.
## How It Works