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?
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With