c - 是否有像 MATLAB 舍入函数这样的 C 舍入函数?

标签 c matlab rounding

我需要一个 C 舍入函数,它像 MATLAB 的舍入函数一样舍入数字。有吗?如果您不知道 MATLAB 的 round 函数是如何工作的,请参阅此链接:

MATLAB round function

我在想我可能只编写自己的简单圆函数来匹配 MATLAB 的功能。

谢谢,

半羊

最佳答案

这听起来类似于 round()来自 math.h 的函数

These functions shall round their argument to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction.

还有 lrint () 它给你一个 int 返回值,尽管 lrint() 和 friend 们遵守当前的舍入方向——你必须使用 fesetround 来设置它。 () ,找到各种舍入方向here .

关于c - 是否有像 MATLAB 舍入函数这样的 C 舍入函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3600747/

相关文章:

c - 传递的指针返回意外错误

python - 同时舍入列表中的单独值

python - 将 float 舍入为 x 位小数?

C: 发送一个 RPC 方法名 + 参数

c - 错误 :"pointer being realloc' d 未分配”在 macOS 上,但在 Windows 上尝试重新分配两次时有效

matlab - 通过从每列可能不同的行中删除一个条目来删除矩阵中的一行

matlab - matlab运算符 "|"是什么意思?

c# - C# 中的 double 、整数、Math.Round

计算包含 1 的子集的数量

matlab - 为什么 MATLAB 的 permute 不需要额外的内存?