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.
JM 18.4 リファレンス ソフトウェア コードを読んで、次の表現に出くわしました。
return ((int) floor(nbits * p_quad->m_Qc + 0.5))
タイプは次のとおりです。
int nbits int p_quad->m_Qc
なぜ 0.5 を加算してから、2 つの整数の乗算をフロアにするのでしょうか? 結果を調べると、それらは乗算だけと同じです。
一般に、floor(x + 0.5)をエミュレートするために使用できますround(x)。ただし、これはx整数以外の値を取ることができる場合にのみ役立つため、あなたの場合は不要に思えます!
floor(x + 0.5)
round(x)
x