【发布时间】:2020-01-24 09:26:19
【问题描述】:
我正在 Visual Studio 中编写一个项目,然后我使用 GCC 来编译它。有时它会导致一些问题:这次我不能使用 sqrtf 函数,因为 VS 接受它但 GCC 不接受。所以我需要找到某种方法(也许是计算平方根的数学方法)以 GCC 和 VS 都接受的方式找到某个数字的平方根。更准确地说,这是导致问题的行:
float x_f = circleRadius - sqrtf((float)((circleRadius * circleRadius) - (y * y)));
我需要求 (circleRadius^2 - y^2) 的平方根
【问题讨论】:
-
To be more precise this is the line which causes a problem哪一个?链接器错误?语法错误? -
你试过std::sqrt吗? en.cppreference.com/w/cpp/numeric/math/sqrt
-
请提供详细信息。
sqrtf肯定是所有编译器都提供的。 -
请提供问题的minimal reproducible example。
sqrtf肯定是可用的,至少从 C++11 开始。另请注意,显式强制转换是多余的。std::sqrtf已经将参数隐式转换为float。
标签: c++ visual-studio gcc