[
https://issues.apache.org/jira/browse/DAFFODIL-2473?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17337738#comment-17337738
]
Samarth Sah commented on DAFFODIL-2473:
---------------------------------------
Hi Mike,
Thank You for adding me.
I have tried to implement left shift.Let me know if I am on the right track.
Also would like to know for ADD,OR,XOR do I have to implement abstract
class FNTwoArgs.
Will also be grateful if you let me know about the testing part.
Thanks in Advance.
case class FNLeftShift(recipe: CompiledDPath, argType: NodeInfo.Kind)
extends FNOneArg(recipe, argType) {
override def computeValue(value: DataValuePrimitive, dstate: DState)
= argType match {
case NodeInfo.Decimal => {
schemaDefinitionError("bitwise add not supported for decimal")
}
case NodeInfo.Float => schemaDefinitionError("bitwise add not
supported for decimal")
case NodeInfo.Double => schemaDefinitionError("bitwise add not
supported for Double")
case NodeInfo.Integer => schemaDefinitionError("bitwise add not
supported for Integer")
case NodeInfo.Long=>{
val leftShift=asLong(value.getAnyRef).longValue()
leftShift<<1
}
case NodeInfo.Int=>{
val leftShift=asInt(value.getAnyRef).intValue()
leftShift<<1
}
case NodeInfo.Short=>{
val leftShift=asShort(value.getAnyRef).shortValue()
leftShift<<1
}
case NodeInfo.Byte=>{
val leftShift=asByte(value.getAnyRef).byteValue()
leftShift<<1
}
case _ => Assert.invariantFailed(String.format("bitwise add not
supported", argType))
}
}
Thank You,
Samarth Sah
On Thu, Apr 29, 2021 at 6:28 PM Mike Beckerle (Jira) <[email protected]>
> Need bit-wise AND, OR, NOT, and shift operations
> ------------------------------------------------
>
> Key: DAFFODIL-2473
> URL: https://issues.apache.org/jira/browse/DAFFODIL-2473
> Project: Daffodil
> Issue Type: New Feature
> Components: Back End, Front End
> Affects Versions: 3.0.0
> Reporter: Mike Beckerle
> Priority: Critical
>
> There are a number of data representations DFDL cannot handle because it
> cannot manipulate numbers with sufficient flexibility in expressions.
> We need AND, OR, NOT, maybe XOR, and shift left, shift right, and probably
> arithmetic shift right (which does sign-extension of signed numbers). We
> should add functions for the whole set of them.
> On signed numbers with specific sizes (long, int, short, byte) these should
> behave as if the data was binary in 2s complement representation, i.e., as if
> the most-significant-bit was playing the role of 2s complement sign.
> These operations should all be undefined (Schema Def Error) on decimal,
> integer, and non-negative integer values, as well as float and double.
> Specifically, these operations are defined on long and its subtypes, and
> unsignedLong and its subtypes only.
>
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)