PI / 2f -- Will this have a rounding error?

Could this formula incur a rounding error that causes the +0.5f shift to not work? In other words, could the value ever be, say, -0.00000001?

Is it cleaner to use some sort of mathf absolute value function?

EDIT: Another idea - could one use an unsigned int to get a range of roughly 4 billion and divide the range by that factor at the end to get precise values?

Or is all this just pointless considering you can use a simple if statement to correct the value to 0 if it dips below? What is proper practice vs. practical practice?

Dividing whatever number by a float will always be unprecise, simply because floats are unprecise. You would expect that 2f, is 2.000000000inf. In the compiler this is not possible, so there will be a cutoff value somewhere in the far back decimals. This value makes every math operation with a float unprecise. So you either need to use some absolute value or you need to cut off the unprecise decimals of the float. In many cases this really doesn’t matter though, games is most of the time one of them. Stuff like that mostly becomes relevant in security critical software for Banks etc.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms