logoalt Hacker News

rossant04/23/20254 repliesview on HN

Am I the only one to be annoyed by this...?

while (this->m_fBladeAngle > 6.2831855) { this->m_fBladeAngle = this->m_fBladeAngle - 6.2831855; }

Like, "let's just write a while loop that could turn into an infinite loop coz I'm too lazy to do a division"


Replies

nemothekid04/23/2025

I want to assume that the GTA developers did this hack because it was faster than floating point division on the Playstation 2 or something.

But knowing they were able to they were able to blow up loading GTA5 by 5 minutes by just parsing json with sscanf, I don't have much hope.

show 2 replies
GeoAtreides04/23/2025

I'm willing to bet it was was done for performance reasons, subtraction is cheaper than float point division. Probably the compiler also has some tricks to optimize this further.

There is absolutely no way this could turn into an infinite loop. It could underflow, but for that to happen angle would have to be less than the 2*pi, therefore exiting the loop.

show 2 replies
anal_reactor04/23/2025

Long shot, but maybe if the value is small, then this loop could be faster than division.

show 1 reply
hoten04/23/2025

for real. The author clearly never heard of fmod

show 1 reply