小编use*_*232的帖子

快速逆任意幂根算法实现

许多资料表明,众所周知的快速平方根反算法可以推广到计算任意幂的平方根。不幸的是,我还没有找到这样的C ++实现,而且我也不擅长通过数学自己概括这种方法。您能帮助我做到这一点,还是提供现成的解决方案?我认为这对许多人都是有用的,尤其是在有充分解释的情况下。

这是原始算法,例如,我不太了解需要更改的内容1 /cbrt(x)

float Q_rsqrt( float number )
{
    long i;
    float x2, y;
    const float threehalfs = 1.5F;

    x2 = number * 0.5F;
    y  = number;
    i  = * ( long * ) &y;                       // evil floating point bit level hacking
    i  = 0x5f3759df - ( i >> 1 );               // what the...? 
    y  = * ( float * ) &i;
    y  = y * ( threehalfs - ( x2 * y * y …
Run Code Online (Sandbox Code Playgroud)

c++ optimization square-root

3
推荐指数
1
解决办法
196
查看次数

联合类型的模板专业化

如何专门化union类型模板?假设我有模板功能

template <typename T>
void foo(T value);
Run Code Online (Sandbox Code Playgroud)

如果T不是任何union类型,我想禁止调用此函数。我该如何实现?

c++ union templates sfinae

3
推荐指数
1
解决办法
59
查看次数

标签 统计

c++ ×2

optimization ×1

sfinae ×1

square-root ×1

templates ×1

union ×1