aherbert commented on code in PR #138:
URL: https://github.com/apache/commons-numbers/pull/138#discussion_r1341387578
##########
commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Addition.java:
##########
@@ -44,4 +44,12 @@ public interface Addition<T> {
* @return {@code -this}.
*/
T negate();
+
+ /**
+ * Is this the zero element? Implementations may want to employ more
efficient
+ * means than calling equals on the zero element.
+ *
+ * @return {@code true} if {@code this} equals the result of {@link #zero}.
+ */
+ boolean isZero();
Review Comment:
We can maintain binary compatibility by adding a default method to the
interface:
```java
default boolean isZero() {
return this.equals(one());
}
```
##########
commons-numbers-core/src/main/java/org/apache/commons/numbers/core/Multiplication.java:
##########
@@ -44,4 +44,12 @@ public interface Multiplication<T> {
* @return <code>this<sup>-1</sup></code>.
*/
T reciprocal();
+
+ /**
+ * Is this the neutral element of multiplication? Implementations may want
to
+ * employ more efficient means than calling equals on the one element.
+ *
+ * @return {@code true} if {@code this} equals the result of {@link #one}.
+ */
+ boolean isOne();
Review Comment:
```java
default boolean isOne() {
return this.equals(one());
}
```
##########
commons-numbers-core/src/main/java/org/apache/commons/numbers/core/DD.java:
##########
@@ -1924,6 +1924,18 @@ public DD pow(int n) {
return computePow(x, xx, n);
}
+ /** {@inheritDoc} */
+ @Override
+ public boolean isZero() {
+ return equals(0.0, x) && equals(0.0, xx);
Review Comment:
The methods in this class assume a normalised representation such that `|x|
>= |xx|`. Thus we only need to compare `x` to zero.
Due to the use of binary equality this method will not return true for
`(-0.0, xx)`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]