Hello. Le sam. 4 avr. 2020 à 23:16, <aherb...@apache.org> a écrit : > > This is an automated email from the ASF dual-hosted git repository. > > aherbert pushed a commit to branch master > in repository https://gitbox.apache.org/repos/asf/commons-numbers.git > > commit 08edae944e4abe7ec4b95a72d3791a9f39fb53c8 > Author: Alex Herbert <aherb...@apache.org> > AuthorDate: Sat Apr 4 21:23:08 2020 +0100 > > Remove a branch from equals tests with NaN. > > A bitwise OR of the booleans is true if either boolean is true. Since > they are both already computed then the || operator short circuit (if > first is true) cannot avoid having to compute the second boolean. > > This change converts 3 conditional evaluations to 2 conditional > evaluations.
Is this measurable? Is the difference significant? I'm not actually asking any benchmarking, but such changes should be balanced with the resulting code reduced (IMO) readability. Best, Gilles > --- > .../main/java/org/apache/commons/numbers/core/Precision.java | 12 > ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git > a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java > > b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java > index d60806d..4155b51 100644 > --- > a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java > +++ > b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Precision.java > @@ -177,7 +177,8 @@ public final class Precision { > public static boolean equalsIncludingNaN(float x, float y) { > final boolean xIsNan = Float.isNaN(x); > final boolean yIsNan = Float.isNaN(y); > - return xIsNan || yIsNan ? > + // Combine the booleans with bitwise OR > + return (xIsNan | yIsNan) ? > !(xIsNan ^ yIsNan) : > equals(x, y, 1); > } > @@ -274,7 +275,8 @@ public final class Precision { > public static boolean equalsIncludingNaN(float x, float y, int maxUlps) { > final boolean xIsNan = Float.isNaN(x); > final boolean yIsNan = Float.isNaN(y); > - return xIsNan || yIsNan ? > + // Combine the booleans with bitwise OR > + return (xIsNan | yIsNan) ? > !(xIsNan ^ yIsNan) : > equals(x, y, maxUlps); > } > @@ -302,7 +304,8 @@ public final class Precision { > public static boolean equalsIncludingNaN(double x, double y) { > final boolean xIsNan = Double.isNaN(x); > final boolean yIsNan = Double.isNaN(y); > - return xIsNan || yIsNan ? > + // Combine the booleans with bitwise OR > + return (xIsNan | yIsNan) ? > !(xIsNan ^ yIsNan) : > equals(x, y, 1); > } > @@ -428,7 +431,8 @@ public final class Precision { > public static boolean equalsIncludingNaN(double x, double y, int > maxUlps) { > final boolean xIsNan = Double.isNaN(x); > final boolean yIsNan = Double.isNaN(y); > - return xIsNan || yIsNan ? > + // Combine the booleans with bitwise OR > + return (xIsNan | yIsNan) ? > !(xIsNan ^ yIsNan) : > equals(x, y, maxUlps); > } > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org