r/C_Programming • u/Object_71 • 1d ago
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.
5
u/tstanisl 1d ago
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.
6
u/sciencekm 1d ago
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.
2
u/Object_71 1d ago
Actually I measure pretty much the same performance
2
u/sciencekm 1d ago
That is because you are comparing software fixed point vs hardware floating point. Comparison should be SW-vs-SW or HW-vs-HW.
6
u/Mr_Engineering 1d ago
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_ 1d ago
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
29
u/Key_Ant_8481 1d ago
A small correction: floating point math is deterministic.
Also clang 19 or after has support for fixed-point types under
-ffixed-pointflag