Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 2797

Inconsistent behavior in `std::min(-0.0f,+0.0f)`

$
0
0

This case should be defined consistently. However, ICC (19.0.1) can be made to give inconsistent results. For example, consider the following code:

#include <algorithm>

inline float minwrap(float x, float y) { return std::min(x,y); }

void f(float);
void test() {
    f(std::min(-0.0f,+0.0f)); //Calls `f` with `-0.0f`
    f(minwrap(-0.0f,+0.0f));  //Calls `f` with `+0.0f`
}

As-suggested by the comments, simply wrapping a call to `std::min(...)` (in an `inline` function no less!) is sufficient to reverse which one is returned.


Viewing all articles
Browse latest Browse all 2797