Closed T-eli closed 7 months ago
Thank you for the PR and detailed Unit test.
There's no need for the double conversion, @barspi suggest a simpler solution, just
return (length * lengthAdjusted) / interpreter.getPackedLength(lengthAdjusted);
While you are at it, it would be great to also change the following method:
private int getUninterpretLength(int length, Interpreter interpreter) {
if (length > 0) {
int lengthAdjusted = length + length % 2;
return (length * lengthAdjusted) / interpreter.getPackedLength(lengthAdjusted);
}
return 0;
}
(the one that uses an Interpreter
instead of a BinaryInterpreter
.
Would you like to send a new PR our of your branch or you prefer us to do it? Please confirm.
Hello @ar
I've pushed a new commit with the suggested edits , you should be able to see it added to the PR.
The issue was due to The two operands lengthAdjusted and interpreter.getPackedLength(lengthAdjusted) are both Integers.
the result was calculated using Integer arithmetic resulting in a 0,5 that was always rounded down to 0.
0.5 because AsciiHex packed len is double len
solution is to cast one of the operands to a double to use double arithmetic, then cast result to integer.