From 0b09ace43a06ea3339afcf9ba40dab90a3cfe359 Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Mon, 9 Feb 2009 04:07:44 +0000 Subject: [PATCH] More compact versions of fminf() / fmaxf() Includes a comment on what might appear as magic or incomplete implementation at first sight. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@6603 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/framework/math-help.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/framework/math-help.h b/lib/framework/math-help.h index de84d2900..f45f848bd 100644 --- a/lib/framework/math-help.h +++ b/lib/framework/math-help.h @@ -43,25 +43,15 @@ static inline float fmaxf(float x, float y) { - if (isnan(x) && isnan(y)) - return NAN; - else if (isnan(x)) - return y; - else if (isnan(y)) - return x; - return (x > y ? x : y); + /* Any comparison will return false if either of the arguments are NAN */ + return (x > y || isnan(y) ? x : y); } static inline float fminf(float x, float y) { - if (isnan(x) && isnan(y)) - return NAN; - else if (isnan(x)) - return y; - else if (isnan(y)) - return x; - return (x > y ? y : x); + /* Any comparison will return false if either of the arguments are NAN */ + return (x < y || isnan(y) ? x : y); }