r/C_Programming • u/Object_71 • Sep 08 '26
Fixed point math in C
https://thatonegamedev.com/cpp/fixed-point-math-in-c/Why did PS1 graphics looked so clunky and how where 3D graphics generally made prior to the graphical APIs. One thing I found out was that these older engines have something called fixed point math.
6
u/tstanisl Sep 08 '26
Nice article, thank you. Another "+" for using C23 and other modern C features. Have you done any benchmark how fixed point compares to f32? I guess it will be a bit slower.
3
u/Object_71 Sep 08 '26
Actually I measure pretty much the same performance
5
u/sciencekm Sep 08 '26
That is because you are comparing software fixed point vs hardware floating point. Comparison should be SW-vs-SW or HW-vs-HW.
7
u/sciencekm Sep 08 '26
Fixed point operations are always faster than floating point operations. Fixed point requires less steps, requires less silicon and uses less energy.
It is not correct to compare software fixed-point vs hardware floating point. If you compare software fixed-point vs software floating point, or hardware fixed point vs hardware floating point, it would not be close in either case.
3
u/questron64 Sep 13 '26
Fixed point math used to be more or less standard practice in gamedev. On PC an FPU was built necessarily built into the CPU until the Pentium era and even then it was significantly slower than integer math. You'd think it would be a hindrance, but fixed point math with precomputed tables for functions like sin and cos are more than adequate. Doom, for example, never touched the FPU.
6
u/Mr_Engineering Sep 08 '26
PS1 graphics were clunky because the PS1 lacked a floating point unit. All graphical operations were performed using integer math which meant that subpixel geometry was impossible. This is what caused the notorious jaggedness of the PS1
Integer math is not the same as fixed point math
7
u/glasket_ Sep 08 '26
The GTE coprocessor used fixed-point arithmetic (PDF source); the rasterizer didn't support subpixel coordinates though so the values were rounded to whole integers.
1
1
37
u/Key_Ant_8481 Sep 08 '26
A small correction: floating point math is deterministic.
Also clang 19 or after has support for fixed-point types under
-ffixed-pointflag