当前位置: 首页>>代码示例>>Java>>正文


Java BigInteger.longValue方法代码示例

本文整理汇总了Java中java.math.BigInteger.longValue方法的典型用法代码示例。如果您正苦于以下问题:Java BigInteger.longValue方法的具体用法?Java BigInteger.longValue怎么用?Java BigInteger.longValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.math.BigInteger的用法示例。


在下文中一共展示了BigInteger.longValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encodeCompactBits

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * @see Utils#decodeCompactBits(long)
 */
public static long encodeCompactBits(BigInteger value) {
    long result;
    int size = value.toByteArray().length;
    if (size <= 3)
        result = value.longValue() << 8 * (3 - size);
    else
        result = value.shiftRight(8 * (size - 3)).longValue();
    // The 0x00800000 bit denotes the sign.
    // Thus, if it is already set, divide the mantissa by 256 and increase the exponent.
    if ((result & 0x00800000L) != 0) {
        result >>= 8;
        size++;
    }
    result |= size << 24;
    result |= value.signum() == -1 ? 0x00800000 : 0;
    return result;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:21,代码来源:Utils.java

示例2: calcMemGas

import java.math.BigInteger; //导入方法依赖的package包/类
private long calcMemGas(GasCost gasCosts, long oldMemSize, BigInteger newMemSize, long copySize) {
    long gasCost = 0;

    // Avoid overflows
    if (newMemSize.compareTo(MAX_GAS) == 1) {
        throw Program.Exception.gasOverflow(newMemSize, MAX_GAS);
    }

    // memory gas calc
    long memoryUsage = (newMemSize.longValue() + 31) / 32 * 32;
    if (memoryUsage > oldMemSize) {
        long memWords = (memoryUsage / 32);
        long memWordsOld = (oldMemSize / 32);
        //TODO #POC9 c_quadCoeffDiv = 512, this should be a constant, not magic number
        long memGas = ( gasCosts.getMEMORY() * memWords + memWords * memWords / 512)
                - (gasCosts.getMEMORY() * memWordsOld + memWordsOld * memWordsOld / 512);
        gasCost += memGas;
    }

    if (copySize > 0) {
        long copyGas = gasCosts.getCOPY_GAS() * ((copySize + 31) / 32);
        gasCost += copyGas;
    }
    return gasCost;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:26,代码来源:VM.java

示例3: MFPNumeric

import java.math.BigInteger; //导入方法依赖的package包/类
public MFPNumeric(BigInteger bigIntValue)   {
    mlValue = bigIntValue.longValue();
    int nComparelValue = bigIntValue.compareTo(BigInteger.valueOf(mlValue));
    if (nComparelValue > 0)    {
        mlValue = Long.MAX_VALUE;   // means long overflowed.
    } else if (nComparelValue < 0)    {
        mlValue = Long.MIN_VALUE;   // means long overflowed.
    }
    mdValue = bigIntValue.doubleValue();
    mbigIntegerValue = bigIntValue;
    mbigDecimalValue = new BigDecimal(bigIntValue);
    mType = Type.MFP_INTEGER_VALUE;
    
    // now let's check if this MFPNumeric is an integer and compare it with 0.
    mbIsActuallyInteger = true;
    mdActualValueCompZero = bigIntValue.compareTo(BigInteger.ZERO);
}
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:18,代码来源:MFPNumeric.java

示例4: encodeCompactBits

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * @see CryptoUtils#decodeCompactBits(long)
 */
public static long encodeCompactBits(BigInteger value) {
    long result;
    int size = value.toByteArray().length;
    if (size <= 3)
        result = value.longValue() << 8 * (3 - size);
    else
        result = value.shiftRight(8 * (size - 3)).longValue();
    // The 0x00800000 bit denotes the sign.
    // Thus, if it is already set, divide the mantissa by 256 and increase
    // the exponent.
    if ((result & 0x00800000L) != 0) {
        result >>= 8;
        size++;
    }
    result |= size << 24;
    result |= value.signum() == -1 ? 0x00800000 : 0;
    return result;
}
 
开发者ID:marvin-we,项目名称:crypto-core,代码行数:22,代码来源:CryptoUtils.java

示例5: pageBySql

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * 返回指定对象数据集合,查询字段名或者别名与指定对象字段一致。
 */
@SuppressWarnings({"unchecked"})
public <T> Pagination<T> pageBySql(Class<T> clazz, final CharSequence queryString,
                                   final Object[] values, int pageIndex, int pageSize) {
    SQLQuery sqlQuery = getSession().createSQLQuery(queryString.toString());
    if ((pageSize > 0) && (pageIndex > 0)) {
        sqlQuery.setFirstResult((pageIndex - 1) * pageSize);
        sqlQuery.setMaxResults(pageIndex * pageSize);
    }
    setParameter(sqlQuery, values);
    AddScalar.addSclar(sqlQuery, clazz);
    List<T> items = sqlQuery.list();
    BigInteger rowsCount = (BigInteger) getSingleColumnBySql(getCountStr(queryString.toString()), values);

    Pagination<T> pagination = new Pagination((long) pageIndex, (long) pageSize, rowsCount.longValue());
    pagination.setItems(items);
    return pagination;
}
 
开发者ID:wu05281,项目名称:admin-shiro,代码行数:21,代码来源:DaoSupport.java

示例6: extractChainIdFromV

import java.math.BigInteger; //导入方法依赖的package包/类
private Integer extractChainIdFromV(BigInteger bv) {
  if (bv.bitLength() > 31) {
    return Integer.MAX_VALUE; // chainId is limited to 31 bits, longer are not valid for now
  }
  long v = bv.longValue();
  if (v == LOWER_REAL_V || v == (LOWER_REAL_V + 1)) return null;
  return (int) ((v - CHAIN_ID_INC) / 2);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:9,代码来源:Transaction.java

示例7: checkContestValid

import java.math.BigInteger; //导入方法依赖的package包/类
private void checkContestValid(Map<String, Object> contest) {
    if ((int)contest.get("status") == 1) {
        BigInteger bigInteger = (BigInteger)contest.get("end_time");
        if (bigInteger.longValue()<System.currentTimeMillis()) {
            Long cid = (Long)contest.get("cid");
            int official = (int) contest.get("official");
            closeContest(cid.intValue(), official);
            contest.replace("status", 2);
        }
    }
}
 
开发者ID:Eagle-OJ,项目名称:eagle-oj-api,代码行数:12,代码来源:ContestService.java

示例8: readTimeTag

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Read the time tag and convert it to a Java Date object. A timestamp is a 64 bit number
 * representing the time in NTP format. The first 32 bits are seconds since 1900, the
 * second 32 bits are fractions of a second.
 * @return a Date
 */
private Date readTimeTag() {
	byte[] secondBytes = new byte[8];
	byte[] fractionBytes = new byte[8];
	for (int i = 0; i < 4; i++) {
		// clear the higher order 4 bytes
		secondBytes[i] = 0; fractionBytes[i] = 0;
	}
		// while reading in the seconds & fraction, check if
		// this timetag has immediate semantics
	boolean isImmediate = true;
	for (int i = 4; i < 8; i++) {
		secondBytes[i] = bytes[streamPosition++];
		if (secondBytes[i] > 0)
			isImmediate = false;
	}
	for (int i = 4; i < 8; i++) {
		fractionBytes[i] = bytes[streamPosition++];
		if (i < 7) {
			if (fractionBytes[i] > 0)
				isImmediate = false;
		} else {
			if (fractionBytes[i] > 1)
				isImmediate = false;
		}
	}

	if (isImmediate) return OSCutils.TIMESTAMP_IMMEDIATE;

	BigInteger secsSince1900 = new BigInteger(secondBytes);
	long secsSince1970 =  secsSince1900.longValue() - OSCutils.SECONDS_FROM_1900_to_1970.longValue();
	if (secsSince1970 < 0) secsSince1970 = 0; // no point maintaining times in the distant past
	long fraction = (new BigInteger(fractionBytes).longValue());
		// the next line was cribbed from jakarta commons-net's NTP TimeStamp code
	fraction = (fraction * 1000) / 0x100000000L;
		// I don't where, but I'm losing 1ms somewhere...
	fraction = (fraction > 0) ? fraction + 1 : 0;
	long millisecs = (secsSince1970 * 1000) + fraction;
	return new Date(millisecs);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:46,代码来源:OSCutils.java

示例9: getRealV

import java.math.BigInteger; //导入方法依赖的package包/类
private byte getRealV(BigInteger bv) {
    if (bv.bitLength() > 31) return 0; // chainId is limited to 31 bits, longer are not valid for now
    long v = bv.longValue();
    if (v == LOWER_REAL_V || v == (LOWER_REAL_V + 1)) return (byte) v;
    byte realV = LOWER_REAL_V;
    int inc = 0;
    if ((int) v % 2 == 0) inc = 1;
    return (byte) (realV + inc);
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:10,代码来源:Transaction.java

示例10: getDateOf

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Date values in ASF files are given in 100 ns (10 exp -4) steps since first
 *
 * @param fileTime Time in 100ns since 1 jan 1601
 * @return Calendar holding the date representation.
 */
public static GregorianCalendar getDateOf(final BigInteger fileTime) {
    final GregorianCalendar result = new GregorianCalendar();

    // Divide by 10 to convert from -4 to -3 (millisecs)
    BigInteger time = fileTime.divide(new BigInteger("10"));
    // Construct Date taking into the diff between 1601 and 1970
    Date date = new Date(time.longValue() - DIFF_BETWEEN_ASF_DATE_AND_JAVA_DATE);
    result.setTime(date);
    return result;
}
 
开发者ID:openaudible,项目名称:openaudible,代码行数:17,代码来源:Utils.java

示例11: readUInt64

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Read a fixed UInt32 value from the buffer.
 *
 * @return The UInt32 value.
 */
public long readUInt64() {
    byte[] bytes = new byte[8];

    for (int i = 7; i >= 0; i--) {
        bytes[i] = (byte) (read() & 0xFF);
    }

    BigInteger result = new BigInteger(bytes);
    return result.longValue();
}
 
开发者ID:jcapsule,项目名称:jwebassembly,代码行数:16,代码来源:WasmByteReader.java

示例12: lcm

import java.math.BigInteger; //导入方法依赖的package包/类
private long lcm(final long m, final long n) {
	if (m  == 0 && n == 0) {
		return 0;
	}
	final BigInteger mi = BigInteger.valueOf(m);
	final BigInteger ni = BigInteger.valueOf(n);
	final BigInteger gcd = mi.gcd(ni);
	final BigInteger r = mi.multiply(ni).divide(gcd);
	return r.longValue();
}
 
开发者ID:polarsys,项目名称:time4sys,代码行数:11,代码来源:LongDurationImpl.java

示例13: UInt64

import java.math.BigInteger; //导入方法依赖的package包/类
private UInt64(BigInteger value) {
    rangeCheck(value);

    this.value = value.longValue();
}
 
开发者ID:jcapsule,项目名称:jwebassembly,代码行数:6,代码来源:UInt64.java

示例14: bigToDouble

import java.math.BigInteger; //导入方法依赖的package包/类
static double bigToDouble(BigInteger x) {
  // This is an extremely fast implementation of BigInteger.doubleValue().  JDK patch pending.
  BigInteger absX = x.abs();
  int exponent = absX.bitLength() - 1;
  // exponent == floor(log2(abs(x)))
  if (exponent < Long.SIZE - 1) {
    return x.longValue();
  } else if (exponent > MAX_EXPONENT) {
    return x.signum() * POSITIVE_INFINITY;
  }

  /*
   * We need the top SIGNIFICAND_BITS + 1 bits, including the "implicit" one bit. To make
   * rounding easier, we pick out the top SIGNIFICAND_BITS + 2 bits, so we have one to help us
   * round up or down. twiceSignifFloor will contain the top SIGNIFICAND_BITS + 2 bits, and
   * signifFloor the top SIGNIFICAND_BITS + 1.
   *
   * It helps to consider the real number signif = absX * 2^(SIGNIFICAND_BITS - exponent).
   */
  int shift = exponent - SIGNIFICAND_BITS - 1;
  long twiceSignifFloor = absX.shiftRight(shift).longValue();
  long signifFloor = twiceSignifFloor >> 1;
  signifFloor &= SIGNIFICAND_MASK; // remove the implied bit

  /*
   * We round up if either the fractional part of signif is strictly greater than 0.5 (which is
   * true if the 0.5 bit is set and any lower bit is set), or if the fractional part of signif is
   * >= 0.5 and signifFloor is odd (which is true if both the 0.5 bit and the 1 bit are set).
   */
  boolean increment = (twiceSignifFloor & 1) != 0
      && ((signifFloor & 1) != 0 || absX.getLowestSetBit() < shift);
  long signifRounded = increment ? signifFloor + 1 : signifFloor;
  long bits = (long) ((exponent + EXPONENT_BIAS)) << SIGNIFICAND_BITS;
  bits += signifRounded;
  /*
   * If signifRounded == 2^53, we'd need to set all of the significand bits to zero and add 1 to
   * the exponent. This is exactly the behavior we get from just adding signifRounded to bits
   * directly.  If the exponent is MAX_DOUBLE_EXPONENT, we round up (correctly) to
   * Double.POSITIVE_INFINITY.
   */
  bits |= x.signum() & SIGN_MASK;
  return longBitsToDouble(bits);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:44,代码来源:DoubleUtils.java

示例15: getKeysInRange

import java.math.BigInteger; //导入方法依赖的package包/类
private List<byte[]> getKeysInRange(byte[] start, byte[] stop, long numOfKeys) {
  byte[] aPadded;
  byte[] bPadded;
  Set<byte[]> result = new TreeSet<>(Bytes.BYTES_COMPARATOR);
  if (start.length < stop.length) {
    aPadded = Bytes.padTail(start, stop.length - start.length);
    bPadded = stop;
  } else if (stop.length < start.length) {
    aPadded = start;
    bPadded = Bytes.padTail(stop, start.length - stop.length);
  } else {
    aPadded = start;
    bPadded = stop;
  }
  if (Bytes.compareTo(aPadded, bPadded) >= 0) {
    throw new IllegalArgumentException("b <= a");
  }
  if (numOfKeys <= 0) {
    throw new IllegalArgumentException("numOfKeys cannot be <= 0");
  }

  byte[] prependHeader = {1, 0};
  final BigInteger startBI = new BigInteger(Bytes.add(prependHeader, aPadded));
  final BigInteger stopBI = new BigInteger(Bytes.add(prependHeader, bPadded));

  BigInteger diffBI = stopBI.subtract(startBI);
  long difference = diffBI.longValue();
  if (diffBI.compareTo(new BigInteger(String.valueOf(Long.MAX_VALUE))) > 0) {
    difference = Long.MAX_VALUE;
  }
  byte[] padded = null;
  for (int i = 0; i < numOfKeys; i++) {
    do {
      BigInteger keyBI = startBI.add(BigInteger.valueOf(nextLong(0, difference)));
      padded = keyBI.toByteArray();
      if (padded[1] == 0)
        padded = Bytes.tail(padded, padded.length - 2);
      else
        padded = Bytes.tail(padded, padded.length - 1);
    } while (!result.add(padded));
  }
  return new ArrayList<>(result);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:44,代码来源:MTableScanPerf.java


注:本文中的java.math.BigInteger.longValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。