You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jm...@apache.org on 2018/01/08 03:18:02 UTC
[incubator-plc4x] 06/06: Sort divided by a int is always an int no
need to round up with Math.ceil
This is an automated email from the ASF dual-hosted git repository.
jmclean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit 44e01ea0483f092cc6df9248bb6658211acd82bf
Author: Justin Mclean <jm...@apache.org>
AuthorDate: Mon Jan 8 14:17:48 2018 +1100
Sort divided by a int is always an int no need to round up with Math.ceil
---
.../s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
index 585173f..bd6ea9c 100644
--- a/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
+++ b/plc4j/protocols/s7/src/main/java/org/apache/plc4x/java/s7/netty/S7Protocol.java
@@ -242,7 +242,7 @@ public class S7Protocol extends MessageToMessageCodec<IsoTPMessage, S7Message> {
(messageType == MessageType.ACK_DATA)) {
DataTransportSize dataTransportSize = DataTransportSize.valueOf(userData.readByte());
short length = (dataTransportSize.isSizeInBits()) ?
- (short) Math.ceil(userData.readShort() / 8) : userData.readShort();
+ (short) (userData.readShort() / 8) : userData.readShort();
byte[] data = new byte[length];
userData.readBytes(data);
// Initialize a rudimentary payload (This is updated in the Plc4XS7Protocol class
--
To stop receiving notification emails like this one, please contact
"commits@plc4x.apache.org" <co...@plc4x.apache.org>.
Re: [incubator-plc4x] 06/06: Sort divided by a int is always an int
no need to round up with Math.ceil
Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,
Ping?
Justin
Re: [incubator-plc4x] 06/06: Sort divided by a int is always an int
no need to round up with Math.ceil
Posted by Christofer Dutz <ch...@c-ware.de>.
Yup … exactly
Chris
Am 09.01.18, 09:42 schrieb "Justin Mclean" <ju...@me.com>:
Hi,
> you are correct with your assumption. However as soon as at least one floating point number is used in the equation, the result should be too, so it should be enough to make 8 an 8.0
So this what I was thinking:
(short) Math.ceil(userData.readShort() / 8.0)
Thanks,
Justin
Re: [incubator-plc4x] 06/06: Sort divided by a int is always an int no
need to round up with Math.ceil
Posted by Justin Mclean <ju...@me.com>.
Hi,
> you are correct with your assumption. However as soon as at least one floating point number is used in the equation, the result should be too, so it should be enough to make 8 an 8.0
So this what I was thinking:
(short) Math.ceil(userData.readShort() / 8.0)
Thanks,
Justin
Re: [incubator-plc4x] 06/06: Sort divided by a int is always an int
no need to round up with Math.ceil
Posted by Christofer Dutz <ch...@c-ware.de>.
Hi Justin,
you are correct with your assumption. However as soon as at least one floating point number is used in the equation, the result should be too, so it should be enough to make 8 an 8.0
And no, size in bits is a Boolean and it simply provides information on if the size parameter is the number of bytes (false) or the number of bits (true). And no, if I want to read 3 consecutive bits for example, then we have to transport this in 1 byte, if we read 9 bits, then in 2 and so on.
Chris
Am 08.01.18, 04:24 schrieb "Justin Mclean" <jm...@apache.org>:
Hi,
With this change here:
> DataTransportSize dataTransportSize = DataTransportSize.valueOf(userData.readByte());
> short length = (dataTransportSize.isSizeInBits()) ?
> - (short) Math.ceil(userData.readShort() / 8) : userData.readShort();
> + (short) (userData.readShort() / 8) : userData.readShort();
Math.ceil would never round up as a short divided by an init is never a floating point number.
Do we need to worry about non byte boundaries? i.e. is isSizeInBits always multiple of 8? If not the code will need to be modified as it would still be doing what it was doing before and sometimes missing a byte.
Thanks,
Justin
Re: [incubator-plc4x] 06/06: Sort divided by a int is always an int
no need to round up with Math.ceil
Posted by Justin Mclean <jm...@apache.org>.
Hi,
With this change here:
> DataTransportSize dataTransportSize = DataTransportSize.valueOf(userData.readByte());
> short length = (dataTransportSize.isSizeInBits()) ?
> - (short) Math.ceil(userData.readShort() / 8) : userData.readShort();
> + (short) (userData.readShort() / 8) : userData.readShort();
Math.ceil would never round up as a short divided by an init is never a floating point number.
Do we need to worry about non byte boundaries? i.e. is isSizeInBits always multiple of 8? If not the code will need to be modified as it would still be doing what it was doing before and sometimes missing a byte.
Thanks,
Justin