首页 > 解决方案 > 在使用 nextafter C++ stl 时遇到问题

问题描述

这对我来说似乎有点奇怪,所以如果我做错了什么,请告诉我。

我需要使用该std::nextafter功能。如此处所述: https ://en.cppreference.com/w/cpp/numeric/math/nextafter

我需要包含的标题是<cmath>.

我可以在这里非常简单地使用它:http: //cpp.sh/4z4hw

但是如果我现在在 Visual Studio(2015 编译器 v110)中使用相同的代码,编译会失败,并说 nextafter 不是 std 的成员。

我不知道如何继续,任何帮助将不胜感激。

使用 C++11。

附上我使用的代码。

另请注意,我也使用 std::ceil、std::floor 并且它也是 cmath 的成员,但这似乎工作正常。

float ConfigEngine::adjustRenderRegionVal(int heightOrWidth, float 
  rrVal, uint expectedValue, uint calculatedValue, bool isMin)
 {
    if (calculatedValue < expectedValue)
         rrVal = std::nextafter(rrVal, 1.0f);
    else //is greater
        rrVal = std::nextafter(rrVal, -1.0f);

    uint newRRLowPx;
    if (isMin)
        newRRLowPx = static_cast<uint>(std::floor(rrVal * heightOrWidth));
    else
         newRRLowPx = static_cast<uint>(std::ceil(rrVal * heightOrWidth));

     if (newRRLowPx != expectedValue)
         return adjustRenderRegionVal(heightOrWidth, rrVal, expectedValue, newRRLowPx, isMin);//recursive call

     return rrVal;
}

标签: c++floating-pointstdcmath

解决方案


推荐阅读