jscience
  1. jscience
  2. JSCIENCE-21

LargeInteger does not divide correctly

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: current
    • Fix Version/s: Version 6.0
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      21

      Description

      jscience library extracted from jscience-2.0.2-bin.zip

      I believe the following code demonstrates that LargeInteger does not divide
      correctly. Here is a sample of the program's output:

      (9217606185931515584/161954441449862691)!=57 [should be 56]
      (16475083891424329836/2810987371137388780)!=6 [should be 5]
      (8534018622449872863/147708727792319539)!=58 [should be 57]
      (7072888951213949173/648342459152882543)!=11 [should be 10]
      (16376455804561828267/2811425230967024634)!=6 [should be 5]
      (16917240375943349879/2838040024792267127)!=6 [should be 5]
      (15045338401104814654/1279896916674992443)!=12 [should be 11]
      (6921376482826465279/1430831844363750300)!=5 [should be 4]
      (6946363172244109552/1404895634681028522)!=5 [should be 4]
      (16813546007473112981/2818507152821681817)!=6 [should be 5]
      (4185418287234793082/700354163750523430)!=6 [should be 5]
      (8817864746618328273/304151288427870331)!=29 [should be 28]
      (17669916401019691125/609566929468492839)!=29 [should be 28]
      (8765113856776173058/628291992304459291)!=14 [should be 13]
      (16149526945103683717/2827992377105391193)!=6 [should be 5]
      (12222782180286854808/611243817909554357)!=20 [should be 19]
      (8284872937031944609/1436681084152847979)!=6 [should be 5]
      (16340494462517080565/1268438042085910178)!=13 [should be 12]
      (15152400804562759455/1295764482551941616)!=12 [should be 11]

      import java.math.BigInteger;
      import java.util.Random;
      import org.jscience.mathematics.numbers.LargeInteger;

      class LargeIntegerScrewup {

      public static BigInteger BigIntegerBIT64=
      BigInteger.ONE.shiftLeft(63);

      public static BigInteger u64toBigInteger(long i)

      { if (i>=0) return BigInteger.valueOf(i); return BigInteger.valueOf(i & 0x7FFFFFFFFFFFFFFFL). add(BigIntegerBIT64); }

      public static LargeInteger LargeIntegerBIT64=
      LargeInteger.ONE.shiftLeft(63);

      public static LargeInteger u64toLargeInteger(long i)

      { if (i>=0) return LargeInteger.valueOf(i); return LargeInteger.valueOf(i & 0x7FFFFFFFFFFFFFFFL). plus(LargeIntegerBIT64); }

      public static void main(String[] args) {
      Random rand=new Random();

      while (true) {
      long u64a=rand.nextLong();
      long u64b=rand.nextLong();

      BigInteger u64d=u64toBigInteger(u64a);
      BigInteger u64e=u64toBigInteger(u64b);
      BigInteger u64f=u64d.divide(u64e);
      long compare1=u64f.longValue();

      LargeInteger u64g=u64toLargeInteger(u64a);
      LargeInteger u64h=u64toLargeInteger(u64b);
      LargeInteger u64i=u64g.divide(u64h);
      long compare2=u64i.longValue();

      if (u64d.longValue()!=u64g.longValue() ||
      u64e.longValue()!=u64h.longValue())

      { throw new RuntimeException("Error in bignum generation"); }

      if (compare1!=compare2)
      System.out.println("("u64d"/"u64e")!="u64i
      " [should be "+u64f+"]");
      }
      }
      }

        Activity

        Hide
        adamw added a comment -

        Accidentally inverted priority tag.

        Show
        adamw added a comment - Accidentally inverted priority tag.
        Hide
        dautelle added a comment -

        Fixed in 3.0.2

        Show
        dautelle added a comment - Fixed in 3.0.2

          People

          • Assignee:
            jscience-issues
            Reporter:
            adamw
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: