Floating point precision loss

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 217 will be converted to 16 777 216.00
16 777 219 will be converted to 16 777 220.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

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.