當前位置: 首頁>>代碼示例>>Java>>正文


Java BigDecimal.abs方法代碼示例

本文整理匯總了Java中java.math.BigDecimal.abs方法的典型用法代碼示例。如果您正苦於以下問題:Java BigDecimal.abs方法的具體用法?Java BigDecimal.abs怎麽用?Java BigDecimal.abs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.math.BigDecimal的用法示例。


在下文中一共展示了BigDecimal.abs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: castToString

import java.math.BigDecimal; //導入方法依賴的package包/類
public static String castToString(BigDecimal val)
{
	int sign = val.signum();
	val = val.abs();
	String s = val.unscaledValue().toString();
	while (s.length() <= val.scale()) s = "0" + s;
	while (s.length() < -val.scale()) s = s + "0";
	if (val.scale() > 0) {
	s = s.substring(0, s.length() - val.scale()) + "." + s.substring(s.length() - val.scale(), s.length());
	   while (s.endsWith("0")) s = s.substring(0, s.length() - 1);
	   if (s.endsWith(".")) s = s.substring(0, s.length() - 1);
	}
	if (sign < 0) s = "-" + s;
	return s;
}
 
開發者ID:CenPC434,項目名稱:java-tools,代碼行數:16,代碼來源:CoreTypes.java

示例2: print

import java.math.BigDecimal; //導入方法依賴的package包/類
private void print(BigDecimal value, Locale l) throws IOException {
    if (c == Conversion.HEXADECIMAL_FLOAT)
        failConversion(c, value);
    StringBuilder sb = new StringBuilder();
    boolean neg = value.signum() == -1;
    BigDecimal v = value.abs();
    // leading sign indicator
    leadingSign(sb, neg);

    // the value
    print(sb, v, l, f, c, precision, neg);

    // trailing sign indicator
    trailingSign(sb, neg);

    // justify based on width
    a.append(justify(sb.toString()));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:Formatter.java

示例3: print

import java.math.BigDecimal; //導入方法依賴的package包/類
private void print(BigDecimal value, Locale l) throws IOException {
    if (c == Conversion.HEXADECIMAL_FLOAT)
        failConversion(c, value);
    StringBuilder sb = new StringBuilder();
    boolean neg = value.signum() == -1;
    BigDecimal v = value.abs();
    // leading sign indicator
    leadingSign(sb, neg);

    // the value
    print(sb, v, l, f, c, precision, neg);

    // trailing sign indicator
    trailingSign(sb, neg);

    // justify based on width
    appendJustified(a, sb);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Formatter.java

示例4: encodeNumeric

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
 * Encode a numerical value using the variable-length encoding.
 * @param dst The destination to which encoded digits are written.
 * @param val The value to encode.
 * @param ord The {@link Order} to respect while encoding {@code val}.
 * @return the number of bytes written.
 */
public static int encodeNumeric(PositionedByteRange dst, BigDecimal val, Order ord) {
  final int len, offset = dst.getOffset(), start = dst.getPosition();
  if (null == val) {
    return encodeNull(dst, ord);
  } else if (BigDecimal.ZERO.compareTo(val) == 0) {
    dst.put(ord.apply(ZERO));
    return 1;
  }
  BigDecimal abs = val.abs();
  if (BigDecimal.ONE.compareTo(abs) <= 0) { // abs(v) >= 1.0
    len = encodeNumericLarge(dst, normalize(val));
  } else { // 1.0 > abs(v) >= 0.0
    len = encodeNumericSmall(dst, normalize(val));
  }
  ord.apply(dst.getBytes(), offset + start, len);
  return len;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:25,代碼來源:OrderedBytes.java

示例5: sqrtNewtonRaphson

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
 * Private utility method used to compute the square root of a BigDecimal.
 * See http://www.codeproject.com/Tips/257031/Implementing-SqrtRoot-in-BigDecimal
 * 
 * @author Luciano Culacciatti 
 */
private static BigDecimal sqrtNewtonRaphson(BigDecimal c, BigDecimal xn, BigDecimal precision){
    BigDecimal fx = xn.pow(2).add(c.negate());
    BigDecimal fpx = xn.multiply(new BigDecimal(2));
    BigDecimal xn1 = fx.divide(fpx, 2 * SQRT_DIG.intValue(), RoundingMode.HALF_DOWN);
    xn1 = xn.add(xn1.negate());
    BigDecimal currentSquare = xn1.pow(2);
    BigDecimal currentPrecision = currentSquare.subtract(c);
    currentPrecision = currentPrecision.abs();
    if(currentPrecision.compareTo(precision) <= -1){
        return xn1;
    }
    return sqrtNewtonRaphson(c, xn1, precision);
}
 
開發者ID:Panzer1119,項目名稱:JAddOn,代碼行數:20,代碼來源:JBigNumber.java

示例6: ln

import java.math.BigDecimal; //導入方法依賴的package包/類
BigDecimal ln(BigDecimal z, BigDecimal error){
BigDecimal logz=z;
BigDecimal step=BigDecimal.ONE;
BigDecimal mistake=z;
BigDecimal abs_mistake=z.abs();
  while(abs_mistake.compareTo(error)>0){
    step=step.add(BigDecimal.ONE);
    mistake=mistake.multiply(z).negate();
    logz= logz.add(mistake.divide(step,localMC),localMC);
    abs_mistake=mistake.divide(step,localMC).abs();
  }
return logz;
}
 
開發者ID:mathhobbit,項目名稱:EditCalculateAndChart,代碼行數:14,代碼來源:CalCln.java

示例7: setValue

import java.math.BigDecimal; //導入方法依賴的package包/類
/**
 * 設置表盤數值
 * @param value
 * @return 返回溢出的值
 */
public synchronized BigDecimal setValue(BigDecimal value)
{
	BigDecimal in=value.abs();
	BigDecimal br=new BigDecimal(radix);
	for(int i=rotors.size()-1;i>=0;i--)
	{
		BigDecimal v=new BigDecimal(radix).pow(i);
		BigDecimal count=in.divide(v,3);
		Rotor rotor=rotors.get(i);
		if(count.compareTo(new BigDecimal(0))==0)
		{
			rotor.setCurrenIndex(0);
			in=in.remainder(v);
		}else if(count.compareTo(new BigDecimal(0))>0 && count.compareTo(br)<0)
		{
			rotor.setCurrenIndex(count.intValue());
			in=in.subtract(v.multiply(count));
		}else if(count.compareTo(br)>=0)
		{
			rotor.setCurrenIndex(rotor.getMaxIndex());
			in=in.remainder(v);
			in=in.add(v.multiply(count.subtract(br).add(new BigDecimal(1))));
		}
	}
	return in;
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:32,代碼來源:ClockDial.java

示例8: getSparseFromBigDecimal

import java.math.BigDecimal; //導入方法依賴的package包/類
public static void getSparseFromBigDecimal(BigDecimal input, DrillBuf data, int startIndex, int scale, int precision, int nDecimalDigits) {

        // Initialize the buffer
        for (int i = 0; i < nDecimalDigits; i++) {
          data.setInt(startIndex + (i * integerSize), 0);
        }

        boolean sign = false;

        if (input.signum() == -1) {
            // negative input
            sign = true;
            input = input.abs();
        }

        // Truncate the input as per the scale provided
        input = input.setScale(scale, BigDecimal.ROUND_HALF_UP);

        // Separate out the integer part
        BigDecimal integerPart = input.setScale(0, BigDecimal.ROUND_DOWN);

        int destIndex = nDecimalDigits - roundUp(scale) - 1;

        // we use base 1 billion integer digits for out integernal representation
        BigDecimal base = new BigDecimal(DIGITS_BASE);

        while (integerPart.compareTo(BigDecimal.ZERO) == 1) {
            // store the modulo as the integer value
            data.setInt(startIndex + (destIndex * integerSize), (integerPart.remainder(base)).intValue());
            destIndex--;
            // Divide by base 1 billion
            integerPart = (integerPart.divide(base)).setScale(0, BigDecimal.ROUND_DOWN);
        }

        /* Sparse representation contains padding of additional zeroes
         * so each digit contains MAX_DIGITS for ease of arithmetic
         */
        int actualDigits;
        if ((actualDigits = (scale % MAX_DIGITS)) != 0) {
            // Pad additional zeroes
            scale = scale + (MAX_DIGITS - actualDigits);
            input = input.setScale(scale, BigDecimal.ROUND_DOWN);
        }

        //separate out the fractional part
        BigDecimal fractionalPart = input.remainder(BigDecimal.ONE).movePointRight(scale);

        destIndex = nDecimalDigits - 1;

        while (scale > 0) {
            // Get next set of MAX_DIGITS (9) store it in the DrillBuf
            fractionalPart = fractionalPart.movePointLeft(MAX_DIGITS);
            BigDecimal temp = fractionalPart.remainder(BigDecimal.ONE);

            data.setInt(startIndex + (destIndex * integerSize), (temp.unscaledValue().intValue()));
            destIndex--;

            fractionalPart = fractionalPart.setScale(0, BigDecimal.ROUND_DOWN);
            scale -= MAX_DIGITS;
        }

        // Set the negative sign
        if (sign == true) {
            data.setInt(startIndex, data.getInt(startIndex) | 0x80000000);
        }

    }
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:68,代碼來源:DecimalUtility.java

示例9: getWeights

import java.math.BigDecimal; //導入方法依賴的package包/類
@Override
public List<BigDecimal> getWeights() {

    final List<BigDecimal> retVal = new ArrayList<>();

    final BigDecimal tmpTotalWeight = this.getTotalWeight();

    BigDecimal tmpSum = BigMath.ZERO;
    BigDecimal tmpLargest = BigMath.ZERO;
    int tmpIndexOfLargest = -1;

    final List<BigDecimal> tmpWeights = myBasePortfolio.getWeights();
    BigDecimal tmpWeight;
    for (int i = 0; i < tmpWeights.size(); i++) {

        tmpWeight = tmpWeights.get(i);
        tmpWeight = DIVIDE.invoke(tmpWeight, tmpTotalWeight);
        tmpWeight = myWeightsContext.enforce(tmpWeight);

        retVal.add(tmpWeight);

        tmpSum = tmpSum.add(tmpWeight);

        if (tmpWeight.abs().compareTo(tmpLargest) == 1) {
            tmpLargest = tmpWeight.abs();
            tmpIndexOfLargest = i;
        }
    }

    if ((tmpSum.compareTo(BigMath.ONE) != 0) && (tmpIndexOfLargest != -1)) {
        retVal.set(tmpIndexOfLargest, retVal.get(tmpIndexOfLargest).subtract(tmpSum.subtract(BigMath.ONE)));
    }

    return retVal;
}
 
開發者ID:optimatika,項目名稱:ojAlgo-finance,代碼行數:36,代碼來源:NormalisedPortfolio.java

示例10: decimalOp

import java.math.BigDecimal; //導入方法依賴的package包/類
@Override
public BigDecimal decimalOp() {
    BigDecimal bd = args.get(0).valDecimal();
    if (nullValue = !args.get(0).isNull())
        return bd.abs();
    return null;
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:8,代碼來源:ItemFuncAbs.java

示例11: compareTo

import java.math.BigDecimal; //導入方法依賴的package包/類
protected static double compareTo(BigDecimal bigDecA, BigDecimal bigDecB, double errorScale)    {
    // not check if errorScale is positive or negative or 0, assume it is valid when use.
    // we cannot compare primitive values, we have to use big decimal to compare
    if (bigDecA.compareTo(bigDecB) == 0)    {
        return 0;   // A == B (strictly).
    }
    
    BigDecimal bigDecAbsoluteErr = (errorScale == 1)?BIG_DEC_THE_MAX_ABSOLUTE_ERROR_OF_MFPNUMERIC
            :((errorScale == 0)?BigDecimal.ZERO:BigDecimal.valueOf(THE_MAX_ABSOLUTE_ERROR_OF_MFPNUMERIC * errorScale));
    BigDecimal bigDecRelativeErr = (errorScale == 1)?BIG_DEC_THE_MAX_RELATIVE_ERROR_OF_MFPNUMERIC
            :((errorScale == 0)?BigDecimal.ZERO:BigDecimal.valueOf(THE_MAX_RELATIVE_ERROR_OF_MFPNUMERIC * errorScale));
    
    BigDecimal bigDecAbsAMinusB = bigDecA.subtract(bigDecB).abs();
    BigDecimal bigDecAbsA = bigDecA.abs(), bigDecAbsB = bigDecB.abs();
    if (bigDecAbsAMinusB.compareTo(bigDecAbsoluteErr) <= 0
            && bigDecAbsA.compareTo(bigDecAbsoluteErr) <= 0
            && bigDecAbsB.compareTo(bigDecAbsoluteErr) <= 0) {
        // this is to compare numbers very close to zero
        return 0;
    } else  {
        BigDecimal bigdecDivBy;
        if (bigDecAbsA.compareTo(bigDecAbsB) > 0)	{
            bigdecDivBy = bigDecAbsA;
        } else	{
            bigdecDivBy = bigDecAbsB;
        }
        // need not to worry about bigdecDivBy is 0 because this means A==B==0. A==B has been covered above.
        if (bigdecDivBy.multiply(bigDecRelativeErr).compareTo(bigDecAbsAMinusB) >= 0) {
            return 0;
        } else {
            return bigDecA.compareTo(bigDecB);
        }
    }
}
 
開發者ID:woshiwpa,項目名稱:SmartMath,代碼行數:35,代碼來源:MFPNumeric.java

示例12: abs

import java.math.BigDecimal; //導入方法依賴的package包/類
public static BigDecimal abs(BigDecimal b1) {
  return b1.abs();
}
 
開發者ID:AcadiaSoft,項目名稱:simm-lib,代碼行數:4,代碼來源:BigDecimalUtils.java

示例13: abs

import java.math.BigDecimal; //導入方法依賴的package包/類
@Override
public BigDecimal abs(BigDecimal arg) {
    return arg.abs();
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:5,代碼來源:BigRealAlgebra.java

示例14: realOp

import java.math.BigDecimal; //導入方法依賴的package包/類
public BigDecimal realOp() {
    BigDecimal bd = args.get(0).valReal();
    return bd.abs();
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:5,代碼來源:ItemFuncAbs.java

示例15: abs

import java.math.BigDecimal; //導入方法依賴的package包/類
public static BigDecimal abs(BigDecimal a) { return a.abs(); } 
開發者ID:CenPC434,項目名稱:java-tools,代碼行數:2,代碼來源:Lang.java


注:本文中的java.math.BigDecimal.abs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。