Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 broke 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?

like image 736
Blair Holloway Avatar asked Sep 15 '26 16:09

Blair Holloway


1 Answers

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().

like image 154
njamesp Avatar answered Sep 17 '26 05:09

njamesp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!