mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fdim(), fdimf() and fdiml() radically simplified
@ 2019-12-11  9:55 Stefan Kanthak
  2019-12-11 10:39 ` Szabolcs Nagy
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Kanthak @ 2019-12-11  9:55 UTC (permalink / raw)
  To: musl

Yet another optimisation/simplification in the math subtree.

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

--- -/src/math/fdim.c
+++ +/src/math/fdim.c
@@ -3,8 +3,4 @@
 double fdim(double x, double y)
 {
-        if (isnan(x))
-                return x;
-        if (isnan(y))
-                return y;
-        return x > y ? x - y : 0;
+        return x <= y ? 0.0 : x - y;
 }

--- -/src/math/fdimf.c
+++ +/src/math/fdimf.c
@@ -3,8 +3,4 @@
 float fdimf(float x, float y)
 {
-        if (isnan(x))
-                return x;
-        if (isnan(y))
-                return y;
-        return x > y ? x - y : 0;
+        return x <= y ? 0.0 : x - y;
 }

--- -/src/math/fdiml.c
+++ +/src/math/fdiml.c
@@ -10,8 +10,4 @@
 long double fdiml(long double x, long double y)
 {
-        if (isnan(x))
-                return x;
-        if (isnan(y))
-                return y;
-        return x > y ? x - y : 0;
+        return x <= y ? 0.0 : x - y;
 }



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

* Re: [PATCH] fdim(), fdimf() and fdiml() radically simplified
  2019-12-11  9:55 [PATCH] fdim(), fdimf() and fdiml() radically simplified Stefan Kanthak
@ 2019-12-11 10:39 ` Szabolcs Nagy
  0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2019-12-11 10:39 UTC (permalink / raw)
  To: Stefan Kanthak; +Cc: musl

* Stefan Kanthak <stefan.kanthak@nexgo.de> [2019-12-11 10:55:01 +0100]:
> Yet another optimisation/simplification in the math subtree.

these changes have incorrect fenv behaviour
(they signal the invalid exception on qnan input),
the result is fine though.

> 
> JFTR: I'm NOT subscribed to your mailing list, so CC: me in replies!
> 
> --- -/src/math/fdim.c
> +++ +/src/math/fdim.c
> @@ -3,8 +3,4 @@
>  double fdim(double x, double y)
>  {
> -        if (isnan(x))
> -                return x;
> -        if (isnan(y))
> -                return y;
> -        return x > y ? x - y : 0;
> +        return x <= y ? 0.0 : x - y;
>  }
> 
> --- -/src/math/fdimf.c
> +++ +/src/math/fdimf.c
> @@ -3,8 +3,4 @@
>  float fdimf(float x, float y)
>  {
> -        if (isnan(x))
> -                return x;
> -        if (isnan(y))
> -                return y;
> -        return x > y ? x - y : 0;
> +        return x <= y ? 0.0 : x - y;
>  }
> 
> --- -/src/math/fdiml.c
> +++ +/src/math/fdiml.c
> @@ -10,8 +10,4 @@
>  long double fdiml(long double x, long double y)
>  {
> -        if (isnan(x))
> -                return x;
> -        if (isnan(y))
> -                return y;
> -        return x > y ? x - y : 0;
> +        return x <= y ? 0.0 : x - y;
>  }


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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11  9:55 [PATCH] fdim(), fdimf() and fdiml() radically simplified Stefan Kanthak
2019-12-11 10:39 ` Szabolcs Nagy

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).