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


##########
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;

Review Comment:
   One of the things learned in doing this V feature is that java boxed numbers 
are awful. They have almost nothing in common, and almost nothing works 
polymorphically across them. 
   This was the best thing I could find online for determining if a decimal 
value is actually an integer, and this is awful performance wise since 
stripTrailingZeros creates another BigInteger object just so you can ask about 
its scale. 
   
   There *should* be a better way. But finding it is not easy.  
   
   I will convert this into a comment discussing this issue that the Java 
numbers have almost no polymorphic operations. This was all in service of 
implementing the isZero() method. 



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