开发者

Largest representable negative floating-point number

开发者 https://www.devze.com 2023-01-14 01:55 出处:网络
What is a platform-independent way of specifying the largest representable negative floating-point number?

What is a platform-independent way of specifying the largest representable negative floating-point number?

We found an algorithm that bro开发者_开发技巧ke when run on a PS3's SPU, but worked fine when compiled for the PPU:

float x = -FLT_MAX;
/* stuff */
if (x > 0.0f) {
    // If x is unchanged, code is executed on SPU
}

Essentially, is there a well-defined negative equivalent of FLT_MAX?


You want std::numeric_limits::lowest(), but it is c++0x only, so not very cross platform at the moment.

You definitely don't want std::numeric_limits::min() - that is smallest magnitude, not furthest negative.

If you want something that will always be less than all other doubles, use -numeric_limits<double>::infinity().


Without knowing what's in /* stuff */, I don't think your problem can be fully addressed here.

There's a good set of slides on the problems inherent in floating point calculation here: http://realtimecollisiondetection.net/pubs/GDC07_Ericson_Physics_Tutorial_Numerical_Robustness.ppt - there may be some hint for you in there as to the source of your problem.

IEEE 754 single precision floating point is not the same on the SPU as it is on the PPU - there's a full explanation in chapter 9 of the SPU ISA document available from http://cell.scei.co.jp/e_download.html which also includes the maximum magnitude of a single precision floating point number.

0

精彩评论

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