开发者

`pow` not returning (IEEE)denormalized floating-point numbers?

Why does pow (math.h or cmath) not returning denormalized numbers? For example, this:

float f = pow (2.f, -126);
double d = pow (2.0, -1022);

gives a non-zero answer for f and d, but using a smaller exponent, i.e -127 for f and -1023 for d, returns a zero, although even 2 ^ -149 (for singles) and 2 ^ -1074 (for doubles) are still representable (as IEEE-754 'denormalized').

Compiler is Microsoft's VS2008, debug confi开发者_运维技巧g.


It sounds like VC is flushing denormals. This can be controlled by the following:

#include <float.h>
#pragma fenv_access (on)

int main()
{
    _controlfp(_DN_SAVE, _MCW_DN);
    float f = pow (2.f, -127);
    double d = pow (2.0, -1023);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜