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


Java BigDecimal.negate方法代码示例

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


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

示例1: testBigDecimals

import java.math.BigDecimal; //导入方法依赖的package包/类
public void testBigDecimals() throws IOException
    {
        BigDecimal bigBase = new BigDecimal("1234567890344656736.125");
        final BigDecimal[] input = new BigDecimal[] {
                // 04-Jun-2017, tatu: these look like integral numbers in JSON so can't use:
//                BigDecimal.ZERO,
//                BigDecimal.ONE,
//                BigDecimal.TEN,
                BigDecimal.valueOf(-999.25),
                bigBase,
                bigBase.divide(new BigDecimal("5")),
                bigBase.add(bigBase),
                bigBase.multiply(new BigDecimal("1.23")),
                bigBase.negate()
        };
        ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
        JsonFactory f = JSON_F;
        JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), bytes);
        g.writeStartArray();
        for (int i = 0; i < input.length; ++i) {
            g.writeNumber(input[i]);
        }
        g.writeEndArray();
        g.close();
        byte[] data = bytes.toByteArray();

        _testBigDecimals(f, input, data, 0, 100);
        _testBigDecimals(f, input, data, 0, 3);
        _testBigDecimals(f, input, data, 0, 1);

        _testBigDecimals(f, input, data, 1, 100);
        _testBigDecimals(f, input, data, 2, 3);
        _testBigDecimals(f, input, data, 3, 1);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:AsyncScalarArrayTest.java

示例2: convertSize

import java.math.BigDecimal; //导入方法依赖的package包/类
default BigDecimal convertSize(SideType side, BigDecimal size) {

        if (side == null || size == null) {
            return null;
        }

        if (side == SideType.BUY) {
            return size;
        }

        if (side == SideType.SELL) {
            return size.negate();
        }

        return null;

    }
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:18,代码来源:BitflyerOrder.java

示例3: format

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Formats a BigDecimal to produce a string.
 * @param number    The BigDecimal to format
 * @param result    where the text is to be appended
 * @param delegate notified of locations of sub fields
 * @exception        ArithmeticException if rounding is needed with rounding
 *                   mode being set to RoundingMode.UNNECESSARY
 * @return The formatted number string
 */
private StringBuffer format(BigDecimal number, StringBuffer result,
                            FieldDelegate delegate) {
    if (multiplier != 1) {
        number = number.multiply(getBigDecimalMultiplier());
    }
    boolean isNegative = number.signum() == -1;
    if (isNegative) {
        number = number.negate();
    }

    synchronized(digitList) {
        int maxIntDigits = getMaximumIntegerDigits();
        int minIntDigits = getMinimumIntegerDigits();
        int maxFraDigits = getMaximumFractionDigits();
        int minFraDigits = getMinimumFractionDigits();
        int maximumDigits = maxIntDigits + maxFraDigits;

        digitList.set(isNegative, number, useExponentialNotation ?
            ((maximumDigits < 0) ? Integer.MAX_VALUE : maximumDigits) :
            maxFraDigits, !useExponentialNotation);

        return subformat(result, delegate, isNegative, false,
            maxIntDigits, minIntDigits, maxFraDigits, minFraDigits);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:DecimalFormat.java

示例4: isDoubleOverFlow

import java.math.BigDecimal; //导入方法依赖的package包/类
public static boolean isDoubleOverFlow(final BigDecimal decimal) {
	if (decimal.signum() == 0) {
		return false;
	}

	BigDecimal newDecimal = decimal;
	boolean isPositive = decimal.signum() == 1;
	if (!isPositive) {
		newDecimal = decimal.negate();
	}

	return (newDecimal.compareTo(MIN_DOUBLE_POSITIVE) < 0 || newDecimal
			.compareTo(MAX_DOUBLE_POSITIVE) > 0);
}
 
开发者ID:yaogdu,项目名称:datax,代码行数:15,代码来源:OverFlowUtil.java

示例5: decimalOp

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal decimalOp() {
    BigDecimal bd = args.get(0).valDecimal();
    if (nullValue = args.get(0).isNullValue())
        return null;
    return bd.negate();
}
 
开发者ID:actiontech,项目名称:dble,代码行数:8,代码来源:ItemFuncNeg.java

示例6: next

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal next() {
  BigInteger unscaled = new BigInteger(precision, rng);
  BigDecimal unscaledBD = new BigDecimal(unscaled);
  int scale =
      rng.nextInt(MAX_SCALE - MIN_SCALE + 1) + MIN_SCALE
          - unscaledBD.precision();
  BigDecimal result = new BigDecimal(unscaled, -scale);
  if (rng.nextBoolean()) {
    result = result.negate();
  }
  return result;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:14,代码来源:FloatGenerator.java

示例7: next

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal next() {
  BigInteger unscaled =
      BigInteger.valueOf(rng.nextInt((int) Math.pow(10, precision)));
  BigDecimal value = new BigDecimal(unscaled, scale);
  if (rng.nextBoolean()) {
    value = value.negate();
  }
  return value;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:11,代码来源:BigDecimalGenerator.java

示例8: sanitize

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * <p>Compute <code>value*signum</code> where <code>value==null</code> is treated as <code>value==0</code></p>.
 *
 * @param value Value to sanitize.
 * @param signum 0 to sanitize to 0, > 0 to sanitize to <code>value</code>, < 0 to sanitize to negative <code>value</code>.
 *
 * @return non-null {@link BigDecimal}.
 */
static BigDecimal sanitize(BigDecimal value, int signum) {
    if (signum == 0 || value == null) {
        return ZERO;
    }
    if (signum > 0) {
        return value;
    }
    return value.negate();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:DurationImpl.java

示例9: alignSigns

import java.math.BigDecimal; //导入方法依赖的package包/类
private static void alignSigns(BigDecimal[] buf, int start, int end) {
    // align sign
    boolean touched;

    do { // repeat until all the sign bits become consistent
        touched = false;
        int s = 0; // sign of the left fields

        for (int i = start; i < end; i++) {
            if (s * buf[i].signum() < 0) {
                // this field has different sign than its left field.
                touched = true;

                // compute the number of unit that needs to be borrowed.
                BigDecimal borrow =
                    buf[i].abs().divide(
                        FACTORS[i - 1],
                        BigDecimal.ROUND_UP);
                if (buf[i].signum() > 0) {
                    borrow = borrow.negate();
                }

                // update values
                buf[i - 1] = buf[i - 1].subtract(borrow);
                buf[i] = buf[i].add(borrow.multiply(FACTORS[i - 1]));
            }
            if (buf[i].signum() != 0) {
                s = buf[i].signum();
            }
        }
    } while (touched);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:DurationImpl.java

示例10: setRiskAversion

import java.math.BigDecimal; //导入方法依赖的package包/类
public void setRiskAversion(final Number factor) {

        final BigDecimal tmpFactor = TypeUtils.toBigDecimal(factor);

        if (tmpFactor.signum() == 0) {
            myRiskAversion = DEFAULT_RISK_AVERSION;
        } else if (tmpFactor.signum() < 0) {
            myRiskAversion = tmpFactor.negate();
        } else {
            myRiskAversion = tmpFactor;
        }
    }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:13,代码来源:MarketEquilibrium.java

示例11: decodeBinary

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public final BigDecimal decodeBinary(final BufferReader b) {

  final int len = getUnsignedShort(b);
  final short weight = b.readShort();
  final int sign = getUnsignedShort(b);
  final int displayScale = getUnsignedShort(b);

  // digits are actually unsigned base-10000 numbers (not straight up bytes)
  final short[] digits = new short[len];
  final BigDecimal[] bdDigits = new BigDecimal[digits.length];
  for (int i = 0; i < len; i++) {
    final short value = b.readShort();
    digits[i] = value;
    bdDigits[i] = new BigDecimal(value);
  }

  if (digits.length > 0) {
    BigDecimal unscaled = bdDigits[0];
    for (int j = 1; j < bdDigits.length; j++)
      unscaled = unscaled.scaleByPowerOfTen(EXPONENT).add(bdDigits[j]);

    int firstDigitSize;
    if (digits[0] < 10)
      firstDigitSize = 1;
    else if (digits[0] < 100)
      firstDigitSize = 2;
    else if (digits[0] < 1000)
      firstDigitSize = 3;
    else
      firstDigitSize = 4;

    final int scaleFactor = weight * EXPONENT + firstDigitSize;
    final BigDecimal unsigned = unscaled.movePointLeft(unscaled.precision()).movePointRight(scaleFactor)
        .setScale(displayScale);

    switch (sign) {
      case NUMERIC_POS:
        return unsigned;
      case NUMERIC_NEG:
        return unsigned.negate();
      case NUMERIC_NAN:
        throw new NumberFormatException("Decimal is NaN");
      case NUMERIC_NULL:
        throw new NumberFormatException("Decimal is NUMERIC_NULL");
      default:
        throw new NumberFormatException("Invalid sign");
    }
  } else
    return ZERO;
}
 
开发者ID:traneio,项目名称:ndbc,代码行数:52,代码来源:BigDecimalEncoding.java

示例12: neg

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal neg(BigDecimal arg) {
    return arg.negate();
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:5,代码来源:BigRealAlgebra.java

示例13: negate

import java.math.BigDecimal; //导入方法依赖的package包/类
private static BigDecimal negate(BigDecimal v) {
    return v.negate();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:BasicBigDecimal.java

示例14: testEncodedValueCheck

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Test encoded value check
 */
@Test
public void testEncodedValueCheck() {
  BigDecimal longMax = BigDecimal.valueOf(Long.MAX_VALUE);
  double negInf = Double.NEGATIVE_INFINITY;
  BigDecimal negLarge = longMax.multiply(longMax).negate();
  BigDecimal negMed = new BigDecimal("-10.0");
  BigDecimal negSmall = new BigDecimal("-0.0010");
  long zero = 0l;
  BigDecimal posSmall = negSmall.negate();
  BigDecimal posMed = negMed.negate();
  BigDecimal posLarge = negLarge.negate();
  double posInf = Double.POSITIVE_INFINITY;
  double nan = Double.NaN;
  byte int8 = 100;
  short int16 = 100;
  int int32 = 100;
  long int64 = 100l;
  float float32 = 100.0f;
  double float64 = 100.0d;
  String text = "hello world.";
  byte[] blobVar = Bytes.toBytes("foo");

  int cnt = 0;
  PositionedByteRange buff = new SimplePositionedMutableByteRange(1024);
  for (Order ord : new Order[] { Order.ASCENDING, Order.DESCENDING }) {
    int o;
    o = OrderedBytes.encodeNull(buff, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, negInf, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, negLarge, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, negMed, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, negSmall, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, zero, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, posSmall, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, posMed, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, posLarge, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, posInf, ord); cnt++;
    o = OrderedBytes.encodeNumeric(buff, nan, ord); cnt++;
    o = OrderedBytes.encodeInt8(buff, int8, ord); cnt++;
    o = OrderedBytes.encodeInt16(buff, int16, ord); cnt++;
    o = OrderedBytes.encodeInt32(buff, int32, ord); cnt++;
    o = OrderedBytes.encodeInt64(buff, int64, ord); cnt++;
    o = OrderedBytes.encodeFloat32(buff, float32, ord); cnt++;
    o = OrderedBytes.encodeFloat64(buff, float64, ord); cnt++;
    o = OrderedBytes.encodeString(buff, text, ord); cnt++;
    o = OrderedBytes.encodeBlobVar(buff, blobVar, ord); cnt++;
  }

  buff.setPosition(0);
  assertEquals(OrderedBytes.length(buff), cnt);
  for (int i = 0; i < cnt; i++) {
    assertEquals(OrderedBytes.isEncodedValue(buff), true);
    OrderedBytes.skip(buff);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:58,代码来源:TestOrderedBytes.java

示例15: getConversionPrice

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal getConversionPrice(Key key, CurrencyType currency) {

    if (currency == null) {
        return null;
    }

    if (currency == getInstrumentCurrency(key)) {
        return ONE;
    }

    if (currency == getFundingCurrency(key)) {

        BigDecimal p = getMidPrice(key);

        return p == null ? null : p.negate();

    }

    return null;

}
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:23,代码来源:BitbankContext.java


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