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


Java BigInteger.valueOf方法代码示例

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


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

示例1: completeBlock

import java.math.BigInteger; //导入方法依赖的package包/类
public void completeBlock(Block newBlock, Block parent) {
    processBlock(newBlock, parent);

    newBlock.getHeader().setReceiptsRoot(BlockChainImpl.calcReceiptsTrie(txReceipts));
    newBlock.getHeader().setStateRoot(latestStateRootHash);
    newBlock.getHeader().setGasUsed(totalGasUsed);

    Bloom logBloom = new Bloom();
    for (TransactionReceipt receipt : txReceipts) {
        logBloom.or(receipt.getBloomFilter());
    }

    newBlock.getHeader().setLogsBloom(logBloom.getData());

    BigInteger minGasLimit = BigInteger.valueOf(ConfigHelper.CONFIG.getBlockchainConfig().getCommonConstants().getMinGasLimit());
    BigInteger targetGasLimit = BigInteger.valueOf(ConfigHelper.CONFIG.getTargetGasLimit());
    BigInteger parentGasLimit = new BigInteger(1, parent.getGasLimit());
    BigInteger gasLimit = gasLimitCalculator.calculateBlockGasLimit(parentGasLimit, BigInteger.valueOf(totalGasUsed), minGasLimit, targetGasLimit, false);

    newBlock.getHeader().setGasLimit(gasLimit.toByteArray());
    newBlock.getHeader().setPaidFees(totalPaidFees);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:MinerHelper.java

示例2: testLongIntExact

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Test long-int exact arithmetic by comparing with the same operations using BigInteger
 * and checking that the result is the same as the long truncation.
 * Errors are reported with {@link fail}.
 *
 * @param x first parameter
 * @param y second parameter
 */
static void testLongIntExact(long x, int y) {
    BigInteger resultBig = null;
    final BigInteger xBig = BigInteger.valueOf(x);
    final BigInteger yBig = BigInteger.valueOf(y);

    try {
        // Test multiplyExact
        resultBig = xBig.multiply(yBig);
        long product = Math.multiplyExact(x, y);
        checkResult("long Math.multiplyExact", x, y, product, resultBig);
    } catch (ArithmeticException ex) {
        if (inLongRange(resultBig)) {
            fail("FAIL: long Math.multiplyExact(" + x + " * " + y + ")" + "; Unexpected exception: " + ex);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ExactArithTests.java

示例3: createParameters

import java.math.BigInteger; //导入方法依赖的package包/类
protected X9ECParameters createParameters()
{
    // p = 2^224 (2^32 - 1) + 2^192 + 2^96 - 1
    BigInteger p = fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");
    BigInteger a = fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");
    BigInteger b = fromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");
    byte[] S = Hex.decode("C49D360886E704936A6678E1139D26B7819F7E90");
    BigInteger n = fromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
    BigInteger h = BigInteger.valueOf(1);

    ECCurve curve = new ECCurve.Fp(p, a, b);
    //ECPoint G = curve.decodePoint(Hex.decode("03"
    //+ "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"));
    ECPoint G = curve.decodePoint(Hex.decode("04"
        + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"
        + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5"));

    return new X9ECParameters(curve, G, n, h, S);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:SECNamedCurves.java

示例4: generateRN

import java.math.BigInteger; //导入方法依赖的package包/类
static long[][][] generateRN(int nsize, int rsize) {
  final long[][][] rn = new long[nsize][][];

  for(int i = 0; i < rn.length; i++) {
    rn[i] = new long[rsize + 1][];
    long n = RANDOM.nextLong() & 0xFFFFFFFFFFFFFFFL; 
    if (n <= 1) n = 0xFFFFFFFFFFFFFFFL - n;
    rn[i][0] = new long[]{n};
    final BigInteger N = BigInteger.valueOf(n); 

    for(int j = 1; j < rn[i].length; j++) {
      long r = RANDOM.nextLong();
      if (r < 0) r = -r;
      if (r >= n) r %= n;
      final BigInteger R = BigInteger.valueOf(r); 
      rn[i][j] = new long[]{r, R.multiply(R).mod(N).longValue()};
    }
  }
  return rn;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestModular.java

示例5: oldSlowFactorial

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Previous version of BigIntegerMath.factorial, kept for timing purposes.
 */
private static BigInteger oldSlowFactorial(int n) {
  if (n <= 20) {
    return BigInteger.valueOf(LongMath.factorial(n));
  } else {
    int k = 20;
    return BigInteger.valueOf(LongMath.factorial(k)).multiply(oldSlowFactorial(k, n));
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:BigIntegerMathBenchmark.java

示例6: describeOwnership

import java.math.BigInteger; //导入方法依赖的package包/类
public Map<Token, Float> describeOwnership(List<Token> sortedTokens)
{
    Map<Token, Float> ownerships = new HashMap<Token, Float>();
    Iterator<Token> i = sortedTokens.iterator();

    // 0-case
    if (!i.hasNext())
        throw new RuntimeException("No nodes present in the cluster. Has this node finished starting up?");
    // 1-case
    if (sortedTokens.size() == 1)
        ownerships.put(i.next(), new Float(1.0));
    // n-case
    else
    {
        final BigInteger ri = BigInteger.valueOf(MAXIMUM).subtract(BigInteger.valueOf(MINIMUM.token + 1));  //  (used for addition later)
        final BigDecimal r  = new BigDecimal(ri);
        Token start = i.next();BigInteger ti = BigInteger.valueOf(((LongToken)start).token);  // The first token and its value
        Token t; BigInteger tim1 = ti;                                                                // The last token and its value (after loop)

        while (i.hasNext())
        {
            t = i.next(); ti = BigInteger.valueOf(((LongToken) t).token); // The next token and its value
            float age = new BigDecimal(ti.subtract(tim1).add(ri).mod(ri)).divide(r, 6, BigDecimal.ROUND_HALF_EVEN).floatValue(); // %age = ((T(i) - T(i-1) + R) % R) / R
            ownerships.put(t, age);                           // save (T(i) -> %age)
            tim1 = ti;                                        // -> advance loop
        }

        // The start token's range extends backward to the last token, which is why both were saved above.
        float x = new BigDecimal(BigInteger.valueOf(((LongToken)start).token).subtract(ti).add(ri).mod(ri)).divide(r, 6, BigDecimal.ROUND_HALF_EVEN).floatValue();
        ownerships.put(start, x);
    }

    return ownerships;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:35,代码来源:Murmur3Partitioner.java

示例7:

import java.math.BigInteger; //导入方法依赖的package包/类
@Test
public void num_radix_x_given_plain_data_return_the_equivalent_number_in_base_radix_when_evaluated_in_decreasing_order() {
    int[] plainData = {0, 0, 0, 1, 1, 0, 1, 0};
    BigInteger expectedResult = BigInteger.valueOf(755);
    Integer radix = 5;
    BigInteger result = ComponentFunctions.num(plainData, radix);
    assertThat(result).isEqualTo(expectedResult);
}
 
开发者ID:idealista,项目名称:format-preserving-encryption-java,代码行数:9,代码来源:ComponentFunctionShould.java

示例8: F2x_mul

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Algorithm 2 in "Software Implementation of Elliptic Curve Cryptography
 * Over Binary Fields", D. Hankerson, J.L. Hernandez, A. Menezes.
 */
protected static BigInteger F2x_mul(BigInteger a, BigInteger b) {
	BigInteger c = BigInteger.valueOf(0);
	for (int j = 0; j < a.bitLength(); j++) {
		if (a.testBit(j)) {
			c = c.xor(b);
		}
		b = b.shiftLeft(1);
	}

	return F2x_mod(c);
}
 
开发者ID:sheraz-n,项目名称:Cryptguard,代码行数:16,代码来源:F2m.java

示例9: previousMgpEqualsTarget

import java.math.BigInteger; //导入方法依赖的package包/类
@Test
public void previousMgpEqualsTarget() {
    MinimumGasPriceCalculator mgpCalculator = new MinimumGasPriceCalculator();

    BigInteger prev = BigInteger.valueOf(1000L);
    BigInteger target = BigInteger.valueOf(1000L);

    BigInteger mgp = mgpCalculator.calculate(prev, target);

    Assert.assertTrue(target.compareTo(mgp) == 0);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:12,代码来源:MinimumGasPriceCalculatorTest.java

示例10: optBigInteger

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Get an optional BigInteger associated with a key, or the defaultValue if
 * there is no such key or if its value is not a number. If the value is a
 * string, an attempt will be made to evaluate it as a number.
 *
 * @param key
 *            A key string.
 * @param defaultValue
 *            The default.
 * @return An object which is the value.
 */
public BigInteger optBigInteger(String key, BigInteger defaultValue) {
    Object val = this.opt(key);
    if (NULL.equals(val)) {
        return defaultValue;
    }
    if (val instanceof BigInteger){
        return (BigInteger) val;
    }
    if (val instanceof BigDecimal){
        return ((BigDecimal) val).toBigInteger();
    }
    if (val instanceof Double || val instanceof Float){
        return new BigDecimal(((Number) val).doubleValue()).toBigInteger();
    }
    if (val instanceof Long || val instanceof Integer
            || val instanceof Short || val instanceof Byte){
        return BigInteger.valueOf(((Number) val).longValue());
    }
    // don't check if it's a string in case of unchecked Number subclasses
    try {
        // the other opt functions handle implicit conversions, i.e. 
        // jo.put("double",1.1d);
        // jo.optInt("double"); -- will return 1, not an error
        // this conversion to BigDecimal then to BigInteger is to maintain
        // that type cast support that may truncate the decimal.
        final String valStr = val.toString();
        if(isDecimalNotation(valStr)) {
            return new BigDecimal(valStr).toBigInteger();
        }
        return new BigInteger(valStr);
    } catch (Exception e) {
        return defaultValue;
    }
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:46,代码来源:JSONObject.java

示例11: newDuration

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Obtain a new instance of a {@code Duration}
 * specifying the {@code Duration} as isPositive, years, months, days, hours, minutes, seconds.
 *
 * <p>A {@link DatatypeConstants#FIELD_UNDEFINED} value indicates that field is not set.
 *
 * @param isPositive Set to {@code false} to create a negative duration. When the length
 *   of the duration is zero, this parameter will be ignored.
 * @param years of this {@code Duration}
 * @param months of this {@code Duration}
 * @param days of this {@code Duration}
 * @param hours of this {@code Duration}
 * @param minutes of this {@code Duration}
 * @param seconds of this {@code Duration}
 *
 * @return New {@code Duration} created from the specified values.
 *
 * @throws IllegalArgumentException If the values are not a valid representation of a
 * {@code Duration}: if any of the fields is negative.
 *
 * @see #newDuration(
 *   boolean isPositive,
 *   BigInteger years,
 *   BigInteger months,
 *   BigInteger days,
 *   BigInteger hours,
 *   BigInteger minutes,
 *   BigDecimal seconds)
 */
public Duration newDuration(
        final boolean isPositive,
        final int years,
        final int months,
        final int days,
        final int hours,
        final int minutes,
        final int seconds) {

        // years may not be set
        BigInteger realYears = (years != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) years) : null;

        // months may not be set
        BigInteger realMonths = (months != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) months) : null;

        // days may not be set
        BigInteger realDays = (days != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) days) : null;

        // hours may not be set
        BigInteger realHours = (hours != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) hours) : null;

        // minutes may not be set
        BigInteger realMinutes = (minutes != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) minutes) : null;

        // seconds may not be set
        BigDecimal realSeconds = (seconds != DatatypeConstants.FIELD_UNDEFINED) ? BigDecimal.valueOf((long) seconds) : null;

                return newDuration(
                        isPositive,
                        realYears,
                        realMonths,
                        realDays,
                        realHours,
                        realMinutes,
                        realSeconds
                );
        }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:67,代码来源:DatatypeFactory.java

示例12: newXMLGregorianCalendar

import java.math.BigInteger; //导入方法依赖的package包/类
/**
 * Constructor of value spaces that a
 * {@code java.util.GregorianCalendar} instance would need to convert to an
 * {@code XMLGregorianCalendar} instance.
 *
 * <p>{@code XMLGregorianCalendar eon} and
 * {@code fractionalSecond} are set to {@code null}
 *
 * <p>A {@link DatatypeConstants#FIELD_UNDEFINED} value indicates that field is not set.
 *
 * @param year of {@code XMLGregorianCalendar} to be created.
 * @param month of {@code XMLGregorianCalendar} to be created.
 * @param day of {@code XMLGregorianCalendar} to be created.
 * @param hour of {@code XMLGregorianCalendar} to be created.
 * @param minute of {@code XMLGregorianCalendar} to be created.
 * @param second of {@code XMLGregorianCalendar} to be created.
 * @param millisecond of {@code XMLGregorianCalendar} to be created.
 * @param timezone of {@code XMLGregorianCalendar} to be created.
 *
 * @return {@code XMLGregorianCalendar} created from specified values.
 *
 * @throws IllegalArgumentException If any individual parameter's value is outside the maximum value constraint for the field
 *   as determined by the Date/Time Data Mapping table in {@link XMLGregorianCalendar}
 *   or if the composite values constitute an invalid {@code XMLGregorianCalendar} instance
 *   as determined by {@link XMLGregorianCalendar#isValid()}.
 */
public XMLGregorianCalendar newXMLGregorianCalendar(
        final int year,
        final int month,
        final int day,
        final int hour,
        final int minute,
        final int second,
        final int millisecond,
        final int timezone) {

        // year may be undefined
        BigInteger realYear = (year != DatatypeConstants.FIELD_UNDEFINED) ? BigInteger.valueOf((long) year) : null;

        // millisecond may be undefined
        // millisecond must be >= 0 millisecond <= 1000
        BigDecimal realMillisecond = null; // undefined value
        if (millisecond != DatatypeConstants.FIELD_UNDEFINED) {
                if (millisecond < 0 || millisecond > 1000) {
                        throw new IllegalArgumentException(
                                                "javax.xml.datatype.DatatypeFactory#newXMLGregorianCalendar("
                                                + "int year, int month, int day, int hour, int minute, int second, int millisecond, int timezone)"
                                                + "with invalid millisecond: " + millisecond
                                                );
                }

                realMillisecond = BigDecimal.valueOf((long) millisecond).movePointLeft(3);
        }

        return newXMLGregorianCalendar(
                realYear,
                month,
                day,
                hour,
                minute,
                second,
                realMillisecond,
                timezone
        );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:DatatypeFactory.java

示例13: valInt

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
public BigInteger valInt() {
    String res = args.get(0).valStr();
    if (res == null) {
        nullValue = true;
        return null; /* purecov: inspected */
    }
    nullValue = false;
    return BigInteger.valueOf(res.length() * 8);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:11,代码来源:ItemFuncBitLength.java

示例14: acceptUnsignedInteger

import java.math.BigInteger; //导入方法依赖的package包/类
@Override
void acceptUnsignedInteger(byte v) {
    this.value = BigInteger.valueOf((long) (v & 0xff));
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:5,代码来源:BigIntegerAccept.java

示例15: SignedInteger

import java.math.BigInteger; //导入方法依赖的package包/类
public SignedInteger(long val) {
    this(BigInteger.valueOf(val));
}
 
开发者ID:PumpkinDB,项目名称:pumpkindb-java,代码行数:4,代码来源:SignedInteger.java


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