You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/06/03 22:13:42 UTC
[commons-numbers] 01/03: NUMBERS-161: Special case.
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
commit 056b268a8e168177c9744744cf2f33f6e9c0376b
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Thu Jun 3 23:01:07 2021 +0200
NUMBERS-161: Special case.
---
.../src/main/java/org/apache/commons/numbers/angle/Angle.java | 11 ++++++-----
.../test/java/org/apache/commons/numbers/angle/AngleTest.java | 6 +++++-
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/Angle.java b/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/Angle.java
index 64ea55e..54dcde9 100644
--- a/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/Angle.java
+++ b/commons-numbers-angle/src/main/java/org/apache/commons/numbers/angle/Angle.java
@@ -347,11 +347,12 @@ public abstract class Angle implements DoubleSupplier {
return normalized < hi ?
normalized :
// If value is too small to be representable compared to the
- // floor expression above (ie, if value + x = x), then we may
- // end up with a number exactly equal to the upper bound here.
- // In that case, subtract one from the normalized value so that
- // we can fulfill the contract of only returning results strictly
- // less than the upper bound.
+ // floor expression above (i.e. value + x = x), then we may
+ // end up with a number exactly equal to the upper bound.
+ // In that case, subtract one period from the normalized value
+ // so that the result is strictly less than the upper bound.
+ normalized == hi ?
+ lo : // Ensure that the result is not below the lower bound.
normalized - period;
}
}
diff --git a/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/AngleTest.java b/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/AngleTest.java
index 54ac3e3..92fda4b 100644
--- a/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/AngleTest.java
+++ b/commons-numbers-angle/src/test/java/org/apache/commons/numbers/angle/AngleTest.java
@@ -205,6 +205,10 @@ class AngleTest {
Assertions.assertEquals(x, normalizer.apply(Angle.Rad.of(x)).getAsDouble());
Assertions.assertEquals(above, normalizer.apply(Angle.Rad.of(above)).getAsDouble());
- // Assertions.assertEquals(below + 2 * Math.PI, normalizer.apply(Angle.Rad.of(below)).getAsDouble());
+
+ // "below" is so close to "x" that below + Math.PI = x + Math.PI
+ // In this case, we can't return below + Math.PI because that is exactly equal to the
+ // upper bound of the range. Instead, we must return the lower bound of x.
+ Assertions.assertEquals(x, normalizer.apply(Angle.Rad.of(below)).getAsDouble());
}
}