# Floating point precision loss

**URL:** <https://discourse.ioquake.org/t/floating-point-precision-loss/376>\
**Category:** ioquake3\
**Created:** [October 6, 2014, 7:20am UTC](https://discourse.ioquake.org/t/floating-point-precision-loss/376 "2014-10-06T07:20:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zturtleman](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.ioquake.org/zturtleman/32/718_2.png) [@zturtleman](https://discourse.ioquake.org/u/zturtleman)\
**Post date:** [October 6, 2014, 7:20am UTC](https://discourse.ioquake.org/t/floating-point-precision-loss/376/1 "2014-10-06T07:20:25Z")

</div>

_Originally post by Cyrax on the old phpbb forum._

* * *

There is a known bug when graphics start shuttering at long uptime and I will try to explain its nature.

Renderer of Quake 3 widely uses floating point values almost everywhere, its **32 bit** IEEE 754 in most places where **significand has a precision of _24 bits_**. Which means that it can’t **precisely** represent integer numbers larger than (2^24+1) after int =\> float conversion i.e.

16 777 2 **17** will be converted to 16 777 2 **16**.00  
16 777 2 **19** will be converted to 16 777 2 **20**.00

and things getting worse with time:

123 699 100 =\> 123 699 104.00  
123 699 101 =\> 123 699 104.00  
123 699 102 =\> 123 699 104.00  
123 699 103 =\> 123 699 104.00  
123 699 105 =\> 123 699 104.00  
123 699 106 =\> 123 699 104.00  
123 699 107 =\> 123 699 104.00  
123 699 108 =\> 123 699 104.00

this is a root of graphics shuttering in renderer at high uptimes

So there is some conclusions:

- good one is that renderer can be fixed by just using double precision data types in very few places
- bad one is that we can't fix existing mods where all math remains 32 bit due to qvm, but can fix new mods
- and worst one is that bug presents in exported data structure (float refEntity\_t.shaderTime)

I will try to prepare some patches later, after opening bugzilla ticked

---

<div class="post-metadata">

**Author:** ![ensiform](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.ioquake.org/ensiform/32/234_2.png) [@ensiform](https://discourse.ioquake.org/u/ensiform)\
**Post date:** [October 8, 2014, 9:40pm UTC](https://discourse.ioquake.org/t/floating-point-precision-loss/376/2 "2014-10-08T21:40:23Z")

</div>

Unfortunately you cannot fix the exported data structure ones in cases for ioquake3 compatibility. refdef\_t and refEntity\_t must remain the same size. If anything you would only be able to add to the end of the structure.

No fixing new mods because it would crash old mods.
