当前位置: 首页>>代码示例>>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;未经允许,请勿转载。