r/C_Programming • • 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

29 comments sorted by

View all comments

Show parent comment

3

u/Cats_and_Shit Sep 09 '26

https://llvm.org/docs/LangRef.html#fast-math-flags

No NaNs - Allow optimizations to assume the arguments and result are not NaN. If an argument is a nan, or the result would be a nan, it produces a poison value instead.

https://llvm.org/docs/LangRef.html#poisonvalues

This means that immediate undefined behavior occurs if a poison value is used as an instruction operand that has any values that trigger undefined behavior. Notably this includes (but is not limited to):

https://llvm.org/docs/UndefinedBehavior.html

0

u/not_a_novel_account Sep 09 '26

Agreed on all, it's not random. Fast math requires you not pass NaN to operations. You shouldn't be doing that anyway.

3

u/ericonr Sep 09 '26

The problem is you can't even check for NaN when building under fast-math, because the compiler will throw away your check.