←back to thread

1371 points yett | 2 comments | | HN request time: 0.433s | source
Show context
rossant ◴[] No.43776470[source]
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(4): >>43776533 #>>43776660 #>>43776679 #>>43776703 #
1. anal_reactor ◴[] No.43776703[source]
Long shot, but maybe if the value is small, then this loop could be faster than division.
replies(1): >>43776806 #
2. matsemann ◴[] No.43776806[source]
If the code runs every frame, it's probably always small and does just one iteration once in a while when it wraps over the value.