Boost logo

Boost Users :

Subject: Re: [Boost-users] min and max preferring NaN
From: Rhys Ulerich (rhys.ulerich_at_[hidden])
Date: 2011-03-10 12:28:51


>>> Can anyone suggest a better implementation ...
>>> for a NaN-preferring min or max ...

> template < class T >
> inline const T& minnan( const T& a, const T& b )
> {
>   return a < b || is_nan(a) ? a : b;
> }

That's much cleaner. Thank you Kris. I've tossed my goofy UNLIKELY
macro around the is_nan check just because.

It's interesting that when using this minnan() implementation on a
sequence of values that short circuiting suggests using the
"incumbent" minimum value as the first parameter and the "challenger"
candidate value as the second parameter.

- Rhys


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net