[GitHub] [commons-compress] kinow commented on a change in pull request #247: Use Math.min and Math.max calculations.

2022-02-17 Thread GitBox


kinow commented on a change in pull request #247:
URL: https://github.com/apache/commons-compress/pull/247#discussion_r809431922



##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } else if (z < 0) {
 // Need to use integer overflow here to represent negatives.
-if (cardinality < 4294967296L) {
-z += cardinality;
-} else {
-z += 4294967296L; // this value is equal to (1 << 32).
-}
+// this value is equal to (1 << 32).

Review comment:
   I think the comment needs to be updated to say that `4294967296L` is the 
`1 << 32`, and not `z += Math.min(cardinality, 4294967296L);`.




-- 
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: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-compress] kinow commented on a change in pull request #247: Use Math.min and Math.max calculations.

2022-02-15 Thread GitBox


kinow commented on a change in pull request #247:
URL: https://github.com/apache/commons-compress/pull/247#discussion_r806110136



##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } else if (z < 0) {
 // Need to use integer overflow here to represent negatives.
-if (cardinality < 4294967296L) {
-z += cardinality;
-} else {
-z += 4294967296L; // this value is equal to (1 << 32).
-}
+// this value is equal to (1 << 32).

Review comment:
   Wrong comment, I think. `1 << 32` is `4294967296L`.
   
   
![image](https://user-images.githubusercontent.com/304786/153921096-1dfa799e-b6ce-4bad-aa39-54d7546a6dc8.png)
   
   After this change it could be interpreted as `z` being `1 << 32`. Maybe 
change the text to `4294967296 is 1 << 32` (which helps devs with the 
magic-numbers issue)
   
   

##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } else if (z < 0) {
 // Need to use integer overflow here to represent negatives.
-if (cardinality < 4294967296L) {
-z += cardinality;
-} else {
-z += 4294967296L; // this value is equal to (1 << 32).
-}
+// this value is equal to (1 << 32).

Review comment:
   
![image](https://user-images.githubusercontent.com/304786/153921096-1dfa799e-b6ce-4bad-aa39-54d7546a6dc8.png)
   
   After this change it could be interpreted as `z` being `1 << 32`. Maybe 
change the text to `4294967296 is 1 << 32` (which helps devs with the 
magic-numbers issue)
   
   

##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } else if (z < 0) {
 // Need to use integer overflow here to represent negatives.
-if (cardinality < 4294967296L) {
-z += cardinality;
-} else {
-z += 4294967296L; // this value is equal to (1 << 32).
-}
+// this value is equal to (1 << 32).

Review comment:
   True! I have to get used to jshell. Looks like the integer overflow 
resets the value to `1`. But using longs works the same way as in Python.
   
   
![image](https://user-images.githubusercontent.com/304786/153925028-9d9c2d94-209c-4e6e-a136-e3f5776d68cf.png)
   




-- 
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: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-compress] kinow commented on a change in pull request #247: Use Math.min and Math.max calculations.

2022-02-14 Thread GitBox


kinow commented on a change in pull request #247:
URL: https://github.com/apache/commons-compress/pull/247#discussion_r806130570



##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } else if (z < 0) {
 // Need to use integer overflow here to represent negatives.
-if (cardinality < 4294967296L) {
-z += cardinality;
-} else {
-z += 4294967296L; // this value is equal to (1 << 32).
-}
+// this value is equal to (1 << 32).

Review comment:
   True! I have to get used to jshell. Looks like the integer overflow 
resets the value to `1`. But using longs works the same way as in Python.
   
   
![image](https://user-images.githubusercontent.com/304786/153925028-9d9c2d94-209c-4e6e-a136-e3f5776d68cf.png)
   




-- 
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: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-compress] kinow commented on a change in pull request #247: Use Math.min and Math.max calculations.

2022-02-14 Thread GitBox


kinow commented on a change in pull request #247:
URL: https://github.com/apache/commons-compress/pull/247#discussion_r806110136



##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } else if (z < 0) {
 // Need to use integer overflow here to represent negatives.
-if (cardinality < 4294967296L) {
-z += cardinality;
-} else {
-z += 4294967296L; // this value is equal to (1 << 32).
-}
+// this value is equal to (1 << 32).

Review comment:
   
![image](https://user-images.githubusercontent.com/304786/153921096-1dfa799e-b6ce-4bad-aa39-54d7546a6dc8.png)
   
   After this change it could be interpreted as `z` being `1 << 32`. Maybe 
change the text to `4294967296 is 1 << 32` (which helps devs with the 
magic-numbers issue)
   
   




-- 
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: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-compress] kinow commented on a change in pull request #247: Use Math.min and Math.max calculations.

2022-02-14 Thread GitBox


kinow commented on a change in pull request #247:
URL: https://github.com/apache/commons-compress/pull/247#discussion_r806110136



##
File path: 
src/main/java/org/apache/commons/compress/harmony/pack200/BHSDCodec.java
##
@@ -308,11 +308,8 @@ public boolean encodes(final long value) {
 }
 } else if (z < 0) {
 // Need to use integer overflow here to represent negatives.
-if (cardinality < 4294967296L) {
-z += cardinality;
-} else {
-z += 4294967296L; // this value is equal to (1 << 32).
-}
+// this value is equal to (1 << 32).

Review comment:
   Wrong comment, I think. `1 << 32` is `4294967296L`.
   
   
![image](https://user-images.githubusercontent.com/304786/153921096-1dfa799e-b6ce-4bad-aa39-54d7546a6dc8.png)
   
   After this change it could be interpreted as `z` being `1 << 32`. Maybe 
change the text to `4294967296 is 1 << 32` (which helps devs with the 
magic-numbers issue)
   
   




-- 
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: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org