Package com.google.gwt.lang.LongLibBase

Examples of com.google.gwt.lang.LongLibBase.LongEmul


  public static void testNot() {
    doTestUnary(OP_NOT);
  }

  public static void testNumberOfLeadingZeros() {
    LongEmul longVal0 = fromLong(0xfedcba9876543210L);
    for (int i = 0; i <= 64; i++) {
      assertEquals(i, LongLibBase.numberOfLeadingZeros(longVal0));
      longVal0 = LongLib.shru(longVal0, 1);
    }
  }
View Full Code Here


    System.out.println("ROUND_TRIP");

    for (int i = 0; i < TEST_VALUES.length + RANDOM_TESTS; i++) {
      long longVal0 = (i < TEST_VALUES.length) ? TEST_VALUES[i]
          : rand.nextLong();
      LongEmul longVal1 = fromLong(longVal0);
      long l2 = toLong(longVal1);
      if (longVal0 != l2) {
        fail("longVal0 = " + longVal0 + ", l2 = " + l2);
      }
      if (!toHex(longVal0).equals(toHex(longVal1))) {
        fail("toHex(longVal0) = " + toHex(longVal0) + ", toHex(longVal1) = "
            + toHex(longVal1));
      }
      if (!toHex(longVal0).equals(toHex(l2))) {
        fail("toHex(longVal0) = " + toHex(longVal0) + ", toHex(l2) = "
            + toHex(l2));
      }
      if (!LongLib.toString(longVal1).equals(Long.toString(longVal0))) {
        fail("toString(longVal0) = " + Long.toString(longVal0)
            + ", toString(longVal1) = " + LongLib.toString(longVal1));
      }
    }

    for (int i = 0; i < TEST_VALUES.length + RANDOM_TESTS; i++) {
      double d0 = (i < TEST_VALUES.length) ? TEST_VALUES[i]
          : (rand.nextDouble() - 0.5) * 3.0 * Long.MAX_VALUE;
      long longVal0 = (long) d0;
      LongEmul longVal1 = LongLib.fromDouble(d0);
      long l2 = toLong(longVal1);
      if (longVal0 != l2) {
        fail("d0 = " + d0 + ", longVal0 = " + longVal0 + ", l2 = " + l2);
      }
    }

    for (int i = 0; i < TEST_VALUES.length + RANDOM_TESTS; i++) {
      long longVal0 = i < TEST_VALUES.length ? TEST_VALUES[i] : rand.nextLong();
      // Find a round-trip capable value
      double d0 = longVal0;
      longVal0 = (long) d0;

      LongEmul longVal1 = fromLong(longVal0);
      double d1 = LongLib.toDouble(longVal1);
      LongEmul l2 = LongLib.fromDouble(d1);
      long l3 = toLong(l2);

      if (longVal0 != l3) {
        fail("longVal0 = " + longVal0 + ", d1 = " + d1 + ", l3 = " + l3);
      }
    }

    for (int i = 0; i < TEST_VALUES.length + RANDOM_TESTS; i++) {
      int i0 = i < TEST_VALUES.length ? (int) TEST_VALUES[i] : rand.nextInt();
      long longVal0 = i0;
      LongEmul longVal1 = LongLib.fromInt(i0);
      long l2 = toLong(longVal1);
      if (longVal0 != l2) {
        fail("i0 = " + i0 + ", longVal0 = " + longVal0 + ", l2 = " + l2);
      }
    }
View Full Code Here

  public static void testXor() {
    doTestBinary(OP_XOR);
  }

  private static LongEmul copy(LongEmul longVal) {
    LongEmul result = new LongEmul();
    result.l = longVal.l;
    result.m = longVal.m;
    result.h = longVal.h;
    return result;
  }
View Full Code Here

      refException = true;
    }
    boolean testException = false;
    long result = -2;
    try {
      LongEmul llongVal0 = fromLong(longVal0);
      LongEmul llongVal1 = fromLong(longVal1);
      LongEmul save_llongVal0 = copy(llongVal0);
      LongEmul save_llongVal1 = copy(llongVal1);

      result = toLong(op.test(llongVal0, llongVal1));
      if (!LongLib.eq(llongVal0, save_llongVal0)) {
        System.out.println("Test altered first argument");
      }
View Full Code Here

      fail(op.getName() + ": longVal = " + longVal);
    }
  }

  private static LongEmul fromLong(long longVal) {
    LongEmul result = new LongEmul();
    result.l = (int) (longVal & LongLibBase.MASK);
    result.m = (int) ((longVal >> LongLibBase.BITS) & LongLibBase.MASK);
    result.h = (int) ((longVal >> (2 * LongLibBase.BITS)) & LongLibBase.MASK_2);
    return result;
  }
View Full Code Here

        + LongLib.toString(actual), LongLib.eq(expected, actual));
  }

  public void testAdditive() {
    {
      final LongEmul n1 = LongLib.fromInt(1234);
      final LongEmul n2 = LongLib.fromInt(9876);
      assertEquals(LongLib.fromInt(11110), LongLib.add(n1, n2));
      assertEquals(LongLib.fromInt(-8642), LongLib.sub(n1, n2));
    }

    {
      final LongEmul n1 = LongLib.fromInt(-1234);
      final LongEmul n2 = LongLib.fromInt(9876);
      assertEquals(LongLib.fromInt(8642), LongLib.add(n1, n2));
      assertEquals(LongLib.fromInt(-11110), LongLib.sub(n1, n2));
    }

    {
      final LongEmul n1 = LongLib.fromInt(-1234);
      final LongEmul n2 = LongLib.fromInt(-9876);
      assertEquals(LongLib.fromInt(-11110), LongLib.add(n1, n2));
      assertEquals(LongLib.fromInt(8642), LongLib.sub(n1, n2));
    }

    {
      final LongEmul n1 = longFromBits(0x12345678, 0xabcdabcd);
      final LongEmul n2 = longFromBits(0x77773333, 0x22224444);
      assertEquals(longFromBits(0x89ab89ab, 0xcdeff011), LongLib.add(n1, n2));
      assertEquals(longFromBits(0x9abd2345, 0x89ab6789), LongLib.sub(n1, n2));
    }
  }
View Full Code Here

    }
  }

  public void testBitOps() {
    {
      final LongEmul n1 = LongLib.fromInt(1234);
      final LongEmul n2 = LongLib.fromInt(9876);

      assertEquals(LongLib.fromInt(1168), LongLib.and(n1, n2));
      assertEquals(LongLib.fromInt(9942), LongLib.or(n1, n2));
      assertEquals(LongLib.fromInt(8774), LongLib.xor(n1, n2));
      assertEquals(LongLib.fromInt(-1235), LongLib.not(n1));
      assertEquals(LongLib.fromInt(-9877), LongLib.not(n2));
    }

    {
      final LongEmul n1 = LongLib.fromInt(-1234);
      final LongEmul n2 = LongLib.fromInt(9876);
      assertEquals(LongLib.fromInt(8708), LongLib.and(n1, n2));
      assertEquals(LongLib.fromInt(-66), LongLib.or(n1, n2));
      assertEquals(LongLib.fromInt(-8774), LongLib.xor(n1, n2));
      assertEquals(LongLib.fromInt(1233), LongLib.not(n1));
      assertEquals(LongLib.fromInt(-9877), LongLib.not(n2));
    }

    {
      final LongEmul n1 = LongLib.shl(LongLib.fromInt(0x1234), 32);
      final LongEmul n2 = LongLib.shl(LongLib.fromInt(0x9876), 32);
      assertEquals(LongLib.shl(LongLib.fromInt(0x1034), 32),
          LongLib.and(n1, n2));
      assertEquals(LongLib.shl(LongLib.fromInt(0x9a76), 32), LongLib.or(n1, n2));
      assertEquals(LongLib.shl(LongLib.fromInt(0x8a42), 32),
          LongLib.xor(n1, n2));
View Full Code Here

    assertTrue(LongLib.eq(LongLib.fromInt(-10), LongLib.fromInt(-10)));
    assertTrue(!LongLib.neq(LongLib.fromInt(-10), LongLib.fromInt(-10)));

    // the following three comparisons cannot be implemented by
    // subtracting the arguments, because the subtraction causes an overflow
    final LongEmul largeNeg = longFromBits(0x82341234, 0x0);
    final LongEmul largePos = longFromBits(0x12341234, 0x0);
    assertTrue(LongLib.lt(largeNeg, largePos));

    assertTrue(LongLib.lt(Const.MIN_VALUE, LongLib.fromInt(0)));
    assertTrue(LongLib.gt(LongLib.fromInt(0), Const.MIN_VALUE));

    final LongEmul largePosPlusOne = LongLib.add(largePos, LongLib.fromInt(1));

    assertTrue(LongLib.lt(largePos, largePosPlusOne));
    assertTrue(LongLib.lte(largePos, largePosPlusOne));
    assertTrue(!LongLib.eq(largePos, largePosPlusOne));
    assertTrue(!LongLib.gte(largePos, largePosPlusOne));
View Full Code Here

    assertEquals(-10, LongLib.toInt(longFromBits(100, -10)));
    assertEquals(-10, LongLib.toInt(longFromBits(-100000, -10)));
  }

  public void testDiv() {
    LongEmul deadBeef = longFromBits(0xdeadbeef, 0xdeadbeef);
    LongEmul ten = LongLib.fromInt(10);
    assertEquals(longFromBits(0xfcaaf97e, 0x63115fe5), LongLib.div(
        deadBeef, ten));
    assertEquals(Const.ZERO, LongLib.div(Const.ONE, Const.TWO));
    assertEquals(longFromBits(0x3fffffff, 0xffffffff), LongLib.div(
        Const.MAX_VALUE, Const.TWO));
View Full Code Here

    LongLib.div(Const.MAX_VALUE, longFromBits(0x00000000, 0x30000300));
    LongLib.div(Const.MAX_VALUE, longFromBits(0x00300000, 0x30000300));
  }

  public void testFactorial() {
    LongEmul fact18 = fact(LongLib.fromInt(18));
    LongEmul fact17 = fact(LongLib.fromInt(17));
    assertEquals(LongLib.fromInt(18), LongLib.div(fact18, fact17));
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.lang.LongLibBase.LongEmul

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.