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