GLM openGL Mathematics fastSqrt function
GLM openGL Mathematics fastSqrt function
此代码
#include "glm/glm.hpp"
#include "glm/gtx/fast_square_root.hpp"
double temp = 4.0;
temp = glm::fastSqrt(temp);
产生以下结果
-2.16802e-058
我做错了什么?
解决方案很简单,滚动自己的fastSqrt
,有效:
#if defined(__SSE__)
template <typename T>
inline T fastSqrt(T const x)
{
float r;
_mm_store_ss(&r, _mm_rsqrt_ss(_mm_set_ss(x)));
return x * r * (T(1.5) - T(.5) * x * r * r);
}
#elif defined(__ARM_NEON__)
template <typename T>
inline T fastSqrt(T const x)
{
auto const r(vrsqrte_f32(float32x2_t{float32_t(x)}));
return x * r[0] * (T(1.5) - T(.5) * x * r[0] * r[0]);
}
#else
template <typename T>
inline T fastSqrt(T const x)
{
constexpr ::std::int32_t const SQRT_MAGIC_F(0x5f3759df);
float r(x);
reinterpret_cast<::std::int32_t&>(r) = SQRT_MAGIC_F -
(reinterpret_cast<::std::int32_t const&>(r) >> 1);
return x * r * (1.5f - .5f * x * r * r);
}
相关文章:
- "error: no matching function for call to"构造函数错误
- 调用专用模板时出错"no matching function for call to [...]"
- 库函数需要一个 std::function<void(void)>,如何传入类函数?
- Confusion: decltype vs std::function
- 为什么 std::function 可以作为 std::not2 的参数?
- 'max'匹配'std::function<const int &(const int &, const int &)>'无过载
- 传递给std::function template的template参数究竟代表什么
- 将带有unique_ptr的可变 lambda 传递给 const&std::function
- 绑定派生类方法C++从实例范围之外的分隔 std::function 变量调用
- "no matching function for call to 'Vector::Vector'"错误
- 如何在向量中删除 std::function<void()>?
- 不断"Attempting to reference a deleted function"
- 将函数包装器转换为 std::function
- 类型擦除的std::function与虚拟函数调用的开销
- C++ std::function 对于类 exept 的所有实例都是空的(只有 Visual2019 编译器问题)
- 如果模板没有可变参数,则 Lambda 被推导出为 std::function
- 我在 ifstream input_file(文件名)行中收到错误"no matching function to call";
- 模板规范获取'Ambiguous call to overloaded function'
- 将 lambda 表达式传递给 std::function in C++
- GLM openGL Mathematics fastSqrt function