【问题标题】:difference dev-cpp and Microsoft Visual C++ math.hdev-cpp 和 Microsoft Visual C++ math.h 的区别
【发布时间】:2012-01-09 03:10:04
【问题描述】:

几天前,我从事 VC++ 项目。我发现,VC++ 中的 math.h 与 dev-cpp math.h 有很大不同。特别是它的 round 函数,它在 Visual C++ math.h 中不存在,但包含在 dev-cpp math.h 中。

现在我想问一下,这是否是由myngw中的dev-cpp根引起的?或者它是否是不同的标准 (ISO)

感谢大家的回复。

【问题讨论】:

    标签: c++ visual-c++ rounding dev-c++ math.h


    【解决方案1】:

    round() 是 C99 标准的一部分,Visual Studio 不完全支持该标准。但是您可以轻松编写自己的实现:

    double round(double r) {
        return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
    }
    

    【讨论】:

    • 编写您自己的轮函数是a hard problem,您的解决方案将无法发挥一定的价值,正如链接答案所解释的那样。一个例子是0.49999999999999994。更好的建议是使用 boost。
    • 或者使用 Visual Studio 2013。微软在该版本中添加了许多 C99 函数,包括(最终)round()
    猜你喜欢
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    相关资源
    最近更新 更多