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.
72
Upvotes
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-pointflag6
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/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
1
u/71d1 Sep 09 '26
Never knew of fix16 until now, really cool article!