我正在用 C 语言实现伪代码:
delay = ROUND(64*(floatDelay - intDelay))
where intDelay = (int) floatDelay
floatDelay 始终为正值。使用 math.h 中的 round 函数有优势吗:
#inlcude <math.h>
delay=(int) round(64*(floatDelay-intDelay));
或者我可以使用:
delay=(int)(64*(floatDelay - intDelay) + 0.5))
最佳答案
据我所知没有任何优点,除了转换为 int 对其他程序员来说可能不会立即显而易见,它像 trunc 一样工作...
而对于 round 函数,您的意图很明确。
关于c - C中的舍入快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/421139/