On Sun, 24 Dec 2023 at 17:51, sebb <seb...@gmail.com> wrote:
>
> On Sun, 24 Dec 2023 at 16:58, <aherb...@apache.org> wrote:
> >
> > This is an automated email from the ASF dual-hosted git repository.
> >
> > aherbert pushed a commit to branch master
> > in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
> >
> >
> > The following commit(s) were added to refs/heads/master by this push:
> >      new a15b3e68 Simplify conversion of numbers to unsigned
> > a15b3e68 is described below
> >
> > commit a15b3e68136dd94ea20e4085afc45aa73d46362e
> > Author: Alex Herbert <aherb...@apache.org>
> > AuthorDate: Sun Dec 24 16:57:58 2023 +0000
> >
> >     Simplify conversion of numbers to unsigned
> > ---
> >  .../java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java | 8 
> > ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git 
> > a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
> >  
> > b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
> > index 4063f440..0b4aa797 100644
> > --- 
> > a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
> > +++ 
> > b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
> > @@ -28,6 +28,8 @@ import org.junit.jupiter.api.Test;
> >   *
> >   */
> >  class ArithmeticUtilsTest {
> > +    /** 2^63. */
> > +    private static final BigInteger TWO_POW_63 = 
> > BigInteger.ONE.shiftLeft(63);
> >
> >      @Test
> >      void testGcd() {
> > @@ -538,7 +540,7 @@ class ArithmeticUtilsTest {
> >      }
> >
> >      private static long toUnsignedLong(int number) {
> > -        return number < 0 ? 0x100000000L + (long)number : (long)number;
> > +        return Integer.toUnsignedLong(number);
> >      }
>
> The private method could now be dropped.

I did this, then reverted. IMO it creates more noise in the source
where the method is called as it must be prefixed by "Integer.". This
makes one-liner code go over 120 chars.


>
> >      private static int remainderUnsignedExpected(int dividend, int 
> > divisor) {
> > @@ -550,7 +552,9 @@ class ArithmeticUtilsTest {
> >      }
> >
> >      private static BigInteger toUnsignedBigInteger(long number) {
> > -        return number < 0L ? 
> > BigInteger.ONE.shiftLeft(64).add(BigInteger.valueOf(number)) : 
> > BigInteger.valueOf(number);
> > +        return number < 0 ?
> > +            TWO_POW_63.or(BigInteger.valueOf(number & Long.MAX_VALUE)) :
> > +            BigInteger.valueOf(number);
> >      }
> >
> >      private static long remainderUnsignedExpected(long dividend, long 
> > divisor) {
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to