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,然后对两个整数的乘积取底?检查结果,它们与单独的乘法相同。
一般来说,floor(x + 0.5)可以用来模拟round(x). x但是,这仅在可以采用非整数值时才有用,因此在您的情况下似乎是多余的!
floor(x + 0.5)
round(x)
x