Is std::min free and does not cost speed?

Discussion of chess software programming and technical issues.

Moderator: Ras

AlvaroBegue
Posts: 932
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Is std::min free and does not cost speed?

Post by AlvaroBegue »

Rein Halbersma wrote:On a related note, detecting overflow from +INF is hard enough but detecting overflow from INT_MAX is even harder. For Apple users who have been bitten by the Undefined Behavior demons, here's a blog post about Apple's newly released Secure Coding Guide.
True. That's why I would have written it like this:

Code: Select all

Value rbeta = std::min(beta, VALUE_INFINITE - 200) + 200;
In case it's not obvious to everyone, this version would work even if VALUE_INFINITE + 200 is beyond the maximum valid Value.