mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fmax(), fmaxf(), fmaxl(), fmin(), fminf(), fminl() simplified
@ 2019-12-11  9:55 Stefan Kanthak
  2019-12-11 10:49 ` Szabolcs Nagy
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Kanthak @ 2019-12-11  9:55 UTC (permalink / raw)
  To: musl

Still more optimisations/simplifications in the math subtree.

JFTR: I'm NOT subscribed to your mailing list, so CC: me in replies!

--- -/src/math/fmax.c
+++ +/src/math/fmax.c
@@ -3,11 +3,9 @@
 double fmax(double x, double y)
 {
-        if (isnan(x))
+        if (x != x)
                 return y;
-        if (isnan(y))
-                return x;
         /* handle signed zeros, see C99 Annex F.9.9.2 */
-        if (signbit(x) != signbit(y))
+        if (x == y)
                 return signbit(x) ? y : x;
         return x < y ? y : x;
 }

--- -/src/math/fmaxf.c
+++ +/src/math/fmaxf.c
@@ -3,11 +3,9 @@
 float fmaxf(float x, float y)
 {
-        if (isnan(x))
+        if (x != x)
                 return y;
-        if (isnan(y))
-                return x;
         /* handle signed zeros, see C99 Annex F.9.9.2 */
-        if (signbit(x) != signbit(y))
+        if (x == y)
                 return signbit(x) ? y : x;
         return x < y ? y : x;
 }

--- -/src/math/fmaxl.c
+++ +/src/math/fmaxl.c
@@ -10,11 +10,9 @@
 long double fmaxl(long double x, long double y)
 {
-        if (isnan(x))
+        if (x != x)
                 return y;
-        if (isnan(y))
-                return x;
         /* handle signed zeros, see C99 Annex F.9.9.2 */
-        if (signbit(x) != signbit(y))
+        if (x == y)
                 return signbit(x) ? y : x;
         return x < y ? y : x;
 }

--- -/src/math/fmin.c
+++ +/src/math/fmin.c
@@ -3,11 +3,9 @@
 double fmin(double x, double y)
 {
-        if (isnan(x))
+        if (x != x)
                 return y;
-        if (isnan(y))
-                return x;
         /* handle signed zeros, see C99 Annex F.9.9.2 */
-        if (signbit(x) != signbit(y))
+        if (x == y)
                 return signbit(x) ? x : y;
-        return x < y ? x : y;
+        return x > y ? y : x;
 }

--- -/src/math/fminf.c
+++ +/src/math/fminf.c
@@ -3,11 +3,9 @@
 float fminf(float x, float y)
 {
-        if (isnan(x))
+        if (x != x)
                 return y;
-        if (isnan(y))
-                return x;
         /* handle signed zeros, see C99 Annex F.9.9.2 */
-        if (signbit(x) != signbit(y))
+        if (x == y)
                 return signbit(x) ? x : y;
-        return x < y ? x : y;
+        return x > y ? y : x;
 }

--- -/src/math/fminl.c
+++ +/src/math/fminl.c
@@ -10,11 +10,9 @@
 long double fminl(long double x, long double y)
 {
-        if (isnan(x))
+        if (x != x)
                 return y;
-        if (isnan(y))
-                return x;
         /* handle signed zeros, see C99 Annex F.9.9.2 */
-        if (signbit(x) != signbit(y))
+        if (x == y)
                 return signbit(x) ? x : y;
-        return x < y ? x : y;
+        return x > y ? y : x;
 }



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-12-11 22:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11  9:55 [PATCH] fmax(), fmaxf(), fmaxl(), fmin(), fminf(), fminl() simplified Stefan Kanthak
2019-12-11 10:49 ` Szabolcs Nagy
2019-12-11 12:33   ` Stefan Kanthak
2019-12-11 13:16     ` Szabolcs Nagy
2019-12-11 13:25       ` Rich Felker
2019-12-11 21:17       ` Stefan Kanthak
2019-12-11 21:30         ` Rich Felker
2019-12-11 22:25           ` Stefan Kanthak
2019-12-11 22:14         ` Damian McGuckin

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).