jadams-tresys commented on a change in pull request #75: Daffodil 1738 zoned 
decimal
URL: https://github.com/apache/incubator-daffodil/pull/75#discussion_r195508937
 
 

 ##########
 File path: 
daffodil-lib/src/main/scala/org/apache/daffodil/util/DecimalUtils.scala
 ##########
 @@ -335,4 +335,142 @@ object DecimalUtils {
     outArray
   }
 
+  def convertFromAsciiStandard(digit: Int): (Int, Boolean) = {
+    if ((digit >= 48) && (digit <= 57)) // positive 0-9
+      return (digit - 48, false)
+    else if ((digit >= 112) && (digit <= 121)) // negative 0-9
+      return (digit - 112, true)
+    else
+      throw new NumberFormatException("Invalid zoned digit: " + digit)
+  }
 
 Review comment:
   I'll add some javadoc to this.
   For AsciiStandard 0-9 represents overpunched positive 0-9 and p-y represent 
overpunched negative 0-9.  The boolean represents whether or not the digit was 
an overpunched negative. This is needed to handle the possibility of the signed 
digit being a 0.
   
   For example, 123p represents -1230 in AsciiStandard, but the signed 
(overpunched) digit is a 0.  With the other digits I had originally just 
returned a negative version of them, but -0 == 0, so I needed some way to 
convey the fact that we are dealing with a negative number back to the where 
this function was called.
   
   I will update the conversion functions to take chars instead of ints, as 
that will be more clear.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to