Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のコードとは対照的に、DirectX ベクトル マグニチュード演算関数の使用に大きな違いはありますか?
float hyp = sqrt(pow(globalVector.x, 2) + pow(globalVector.y, 2))
あなたが気にするのに十分ではありません。
あなたが投稿した機能に私がお勧めする改善があります。
累乗関数を呼び出す必要はありません。x*xそして、y*y同じくらい良くて安くなります。
x*x
y*y
次の疑似コードのように、スケーリングによって丸めから保護します。
if (abs(x) > abs(y)) { r = abs(y/x); hyp = x*sqrt(1 + r*r); } else { r = abs(x/y); hyp = y*sqrt(1 + r*r); }