mbeckerle commented on code in PR #900:
URL: https://github.com/apache/daffodil/pull/900#discussion_r1059405476


##########
daffodil-lib/src/main/scala/org/apache/daffodil/util/Numbers.scala:
##########
@@ -311,4 +311,28 @@ object Numbers {
   def asAnyRef(n: Any): AnyRef = {
     n.asInstanceOf[AnyRef]
   }
+
+  /**
+   * This is the official way to tell if a JBigDecimal has an integer value.
+   * @param bd A Java BigDecimal
+   * @return true if the value is an integer (has fraction part == 0).
+   */
+  def isIntegerValue (bd: JBigDecimal) = {
+     bd.signum() == 0 || bd.scale() <= 0 || bd.stripTrailingZeros().scale() <= 
0;
+  }
+
+  /** For any standard predefined subtype of JNumber, is the value numerically 
zero. */
+  def isZero(n1: JNumber) : Boolean = {
+    n1 match {
+      case d: JDouble => d.doubleValue() == 0.0
+      case f: JFloat => f.floatValue() == 0.0
+      case bd: JBigDecimal => bd.signum() == 0
+      case bi: JBigInt => bi.signum() == 0
+      case l: JLong => l.longValue == 0
+      case i: JInt => i.intValue == 0
+      case s: JShort => s.shortValue == 0
+      case b: JByte => b.byteValue == 0
+    }

Review Comment:
   I will add a default case, as this is supposed to handle the java numbers 
that we use in our internal infoset representation, which does not use any of 
the ones you mention here. 
   
   It was definitely a mistake for Scala to not define its own Number base 
class/trait. One more compromise to reuse of the Java classes. 



-- 
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]

Reply via email to