本文整理汇总了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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
}
示例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;
}
示例12: neg
import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal neg(BigDecimal arg) {
return arg.negate();
}
示例13: negate
import java.math.BigDecimal; //导入方法依赖的package包/类
private static BigDecimal negate(BigDecimal v) {
return v.negate();
}
示例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);
}
}
示例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;
}