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


Java BigDecimal.signum方法代码示例

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


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

示例1: toDouble

import java.math.BigDecimal; //导入方法依赖的package包/类
public static double toDouble(Object a) {

        double value;

        if (a instanceof java.lang.Double) {
            return ((Double) a).doubleValue();
        } else if (a instanceof BigDecimal) {
            BigDecimal bd = (BigDecimal) a;

            value = bd.doubleValue();

            int        signum = bd.signum();
            BigDecimal bdd    = new BigDecimal(value + signum);

            if (bdd.compareTo(bd) != signum) {
                throw Error.error(ErrorCode.X_22003);
            }
        } else if (a instanceof Number) {
            value = ((Number) a).doubleValue();
        } else {
            throw Error.error(ErrorCode.X_22501);
        }

        return value;
    }
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:26,代码来源:NumberType.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: convertToDouble

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Converter from a numeric object to Double. Input is checked to be
 * within range represented by Double
 */
static Double convertToDouble(Object o) throws HsqlException {

    double val;

    if (o instanceof BigDecimal) {
        BigDecimal bd = (BigDecimal) o;

        val = bd.doubleValue();

        int        signum = bd.signum();
        BigDecimal bo     = new BigDecimal(val + signum);

        if (bo.compareTo(bd) != signum) {
            throw Trace.error(Trace.NUMERIC_VALUE_OUT_OF_RANGE);
        }
    } else {
        val = ((Number) o).doubleValue();
    }

    return ValuePool.getDouble(Double.doubleToLongBits(val));
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:26,代码来源:Column.java

示例4: makeRiskFreeReturn

import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigDecimal makeRiskFreeReturn(final FinancialMarket market) {

            BigDecimal retVal = BigMath.ZERO;

            if (market.isHistoricalRiskFreeReturn()) {
                final CalendarDateSeries<Double> tmpRiskFreeSeries = market.getRiskFreeSeries();
                final Double tmpLastValue = tmpRiskFreeSeries.lastValue();
                retVal = BigFunction.DIVIDE.invoke(new BigDecimal(tmpLastValue), BigMath.HUNDRED);
            }

            final BigDecimal tmpAdjustment = market.getRiskFreeReturnAdjustment();
            if (tmpAdjustment.signum() != 0) {
                retVal = retVal.add(tmpAdjustment);
            }

            return retVal;
        }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:18,代码来源:FinancialMarket.java

示例5: 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:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:DecimalFormat.java

示例6: toBigInteger

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * <p>BigInteger value of BigDecimal value.</p>
 *
 * @param value Value to convert.
 * @param canBeNull Can returned value be null?
 *
 * @return BigInteger value of BigDecimal, possibly null.
 */
private static BigInteger toBigInteger(
    BigDecimal value,
    boolean canBeNull) {
    if (canBeNull && value.signum() == 0) {
        return null;
    }
    else {
        return value.unscaledValue();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:DurationImpl.java

示例7: processCost

import java.math.BigDecimal; //导入方法依赖的package包/类
private void processCost(Player player, String command, Consumer<CommandResult> callback)
{
    int index = command.lastIndexOf(':');
    String currencyName = index < 0 ? "" : command.substring(0, index).toLowerCase();
    BigDecimal cost = new BigDecimal(command.substring(index + 1).replaceFirst("\\s++$", ""));
    VirtualChestEconomyManager economyManager = this.plugin.getEconomyManager();
    boolean isSuccessful = true;
    switch (cost.signum())
    {
    case 1:
        isSuccessful = economyManager.withdrawBalance(currencyName, player, cost);
        break;
    case -1:
        isSuccessful = economyManager.depositBalance(currencyName, player, cost.negate());
        break;
    }
    callback.accept(isSuccessful ? CommandResult.success() : CommandResult.empty());
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:19,代码来源:VirtualChestActions.java

示例8: 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

示例9: calculatePrice

import java.math.BigDecimal; //导入方法依赖的package包/类
@SuppressLint("SetTextI18n")
    private void calculatePrice() {
        if (!viewsLoaded) {
            return;
        }

        String qtyStr = etQuantity.getText().toString();
        if (qtyStr.length() == 0) {
//            mQuantity = null;
            llCalculatedTextZone.setVisibility(View.GONE);
            return;
        }

        llCalculatedTextZone.setVisibility(View.VISIBLE);
        String amountStr = etUserInput.getText().toString();
        if (amountStr.length() > 0) {
            try {
                mEnteredAmount = new BigDecimal(amountStr);
                mQuantity = new BigDecimal(qtyStr);
                if (mQuantity.signum() != 0) {
                    mEnteredPrice = mEnteredAmount.divide(mQuantity, ConstantValues.DECIMALS_PRICE, ConstantValues.ROUNDING_MODE_PRICE);
                    tvCalculatedTextContent.setText(Utils.numberToString(mEnteredPrice, true, ConstantValues.DECIMALS_PRICE, ConstantValues.ROUNDING_MODE_PRICE) + " "
                            + mCurrencyCode);
                } else {
                    mEnteredPrice = null;
                    tvCalculatedTextContent.setText(null);
                }
            } catch (NumberFormatException ignored) {
            }
        } else {
            mEnteredPrice = null;
            tvCalculatedTextContent.setText(null);
        }
    }
 
开发者ID:mkeresztes,项目名称:AndiCar,代码行数:35,代码来源:ExpenseEditFragment.java

示例10: getTargetWeight

import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigDecimal getTargetWeight(final Change aChange) {

            final List<? extends Change> tmpPortfolioChanges = aChange.getWorkSetPortfolio().getChanges();

            final BigDecimal tmpTargetWeight = aChange.getLimit().getTarget();

            BigDecimal tmpFreeWeight = tmpTargetWeight;
            BigDecimal tmpLockedWeight = BigMath.ZERO;

            int tmpFreeCount = 0;
            int tmpLockedCount = 0;

            final InstrumentCategory tmpThisCatgeory = Logic.getEffectiveCategory(aChange);

            for (final Change tmpChange : tmpPortfolioChanges) {
                if (Logic.getEffectiveCategory(tmpChange).equals(tmpThisCatgeory)) {
                    if (tmpChange.getWorkSetInstrument().isLocked()) {
                        tmpLockedWeight = BigFunction.ADD.invoke(tmpLockedWeight, Logic.getCurrentWeight(tmpChange));
                        tmpLockedCount++;
                    } else {
                        tmpFreeCount++;
                    }
                }
            }
            if (tmpLockedWeight.signum() != 0) {
                tmpFreeWeight = BigFunction.SUBTRACT.invoke(tmpFreeWeight, tmpLockedWeight);
            }

            if ((tmpFreeCount == 0) || (tmpLockedCount == 0)) {
                return BigFunction.DIVIDE.invoke(tmpTargetWeight, new BigDecimal(tmpFreeCount + tmpLockedCount));
            } else {
                if (aChange.getWorkSetInstrument().isLocked()) {
                    return Logic.getCurrentWeight(aChange);
                } else {
                    return BigFunction.DIVIDE.invoke(tmpFreeWeight, new BigDecimal(tmpFreeCount));
                }
            }
        }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:39,代码来源:Change.java

示例11: makeDefinitionAsset

import java.math.BigDecimal; //导入方法依赖的package包/类
public static SimpleAsset makeDefinitionAsset(final FinancialMarket.Asset asset, final FinancialMarket market) {

            final GeometricBrownianMotion tmpProc = Logic.makeAnnualisedProcess(asset);

            double tmpReturn = tmpProc.getExpected() - 1.0;
            final double tmpRisk = asset.getVolatility();
            final BigDecimal tmpWeight = asset.getWeight();

            final BigDecimal tmpAdjustment = market.getRiskFreeReturnAdjustment();
            if (tmpAdjustment.signum() != 0) {
                tmpReturn -= tmpAdjustment.doubleValue();
            }

            return new SimpleAsset(tmpReturn, tmpRisk, tmpWeight);
        }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:16,代码来源:FinancialMarket.java

示例12: getLowerLimit

import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigDecimal getLowerLimit(final Change aChange) {

            BigDecimal retVal = BigMath.ZERO;

            final WorkSetPortfolio tmpWorkSetPortfolio = aChange.getWorkSetPortfolio();

            tmpWorkSetPortfolio.getCurrentAmount();
            final BigDecimal tmpNewPortfVal = tmpWorkSetPortfolio.getAdjustedFutureAmount();
            final BigDecimal tmpCurWeight = Logic.getCurrentWeight(aChange);

            if (tmpNewPortfVal.signum() != 0) {
                if (Logic.isLocked(aChange)) {
                    retVal = tmpCurWeight;
                } else if (Logic.isForcedToSell(aChange)) {
                    if (tmpWorkSetPortfolio.getWorkSet().getSellShare() != null) {
                        retVal = BigFunction.DIVIDE.invoke(BigFunction.MULTIPLY.invoke(aChange.getHolding().getAmount(),
                                BigFunction.SUBTRACT.invoke(BigMath.ONE, tmpWorkSetPortfolio.getWorkSet().getSellShare())), tmpNewPortfVal);
                    } else {
                        // It's not specified how much you have to sell
                        if ((Logic.isDefault(aChange))) {
                            retVal = aChange.getLimit().getTarget().subtract(aChange.getLimit().getPrecision());
                        } else {
                            retVal = aChange.getLimit().getLower();
                        }
                    }
                } else if (Logic.isForcedToBuy(aChange)) {
                    retVal = tmpCurWeight; // It's not specified how much you have to buy
                } else if (Logic.isAllowedToSell(aChange)) {
                    if (tmpWorkSetPortfolio.getWorkSet().isFreeToIgnoreProfiles()) {
                        retVal = BigMath.ZERO;
                    } else {
                        if ((Logic.isDefault(aChange))) {
                            retVal = aChange.getLimit().getTarget().subtract(aChange.getLimit().getPrecision()).min(tmpCurWeight);
                        } else {
                            retVal = aChange.getLimit().getLower().min(tmpCurWeight);
                        }
                    }
                } else {
                    retVal = tmpCurWeight;
                }
            }

            return retVal;
        }
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:45,代码来源:Change.java

示例13: divide

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 *  Divide numeric object a by object b.
 *
 * @param  a
 * @param  b
 * @param  type
 * @return result
 * @throws  HsqlException
 */
static Object divide(Object a, Object b, int type) throws HsqlException {

    if (a == null || b == null) {
        return null;
    }

    switch (type) {

        case Types.NULL :
            return null;

        case Types.REAL :
        case Types.FLOAT :
        case Types.DOUBLE : {
            double ad = ((Number) a).doubleValue();
            double bd = ((Number) b).doubleValue();

            return ValuePool.getDouble(Double.doubleToLongBits(ad / bd));
        }
        case Types.NUMERIC :
        case Types.DECIMAL : {
            BigDecimal abd   = (BigDecimal) a;
            BigDecimal bbd   = (BigDecimal) b;
            int        scale = abd.scale() > bbd.scale() ? abd.scale()
                                                         : bbd.scale();

            return (bbd.signum() == 0) ? null
                                       : abd.divide(bbd, scale,
                                       BigDecimal.ROUND_HALF_DOWN);
        }
        case Types.TINYINT :
        case Types.SMALLINT :
        case Types.INTEGER : {
            int ai = ((Number) a).intValue();
            int bi = ((Number) b).intValue();

            if (bi == 0) {
                throw Trace.error(Trace.DIVISION_BY_ZERO);
            }

            return ValuePool.getInt(ai / bi);
        }
        case Types.BIGINT : {
            long longa = ((Number) a).longValue();
            long longb = ((Number) b).longValue();

            return (longb == 0) ? null
                                : ValuePool.getLong(longa / longb);
        }
        default :
            throw Trace.error(Trace.FUNCTION_NOT_SUPPORTED,
                              Types.getTypeString(type));
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:64,代码来源:Column.java

示例14: estimate

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public Estimation estimate(Context context, Request request) {

    Context.Key key = getKey(context, request);

    BigDecimal mid = context.getMidPrice(key);

    if (mid == null) {
        return BAIL;
    }

    BigDecimal deviation = calculateDeviation(context, request);

    if (deviation == null || deviation.signum() <= 0) {
        return BAIL;
    }

    double[] averages = new double[4];

    BigDecimal ceiling = mid.multiply(ONE.add(deviation));

    trimToEmpty(context.getAskPrices(key)).entrySet().stream()
            .filter(e -> e.getValue() != null)
            .filter(e -> e.getKey() != null)
            .filter(e -> e.getKey().compareTo(ceiling) <= 0)
            .forEach(e -> {
                averages[I_NOTIONAL] = averages[I_NOTIONAL] + e.getValue().doubleValue() * e.getKey().doubleValue();
                averages[I_QUANTITY] = averages[I_QUANTITY] + e.getValue().doubleValue();
                averages[I_SIZE_ASK] = averages[I_SIZE_ASK] + e.getValue().doubleValue();
            });

    BigDecimal floor = mid.multiply(ONE.subtract(deviation));

    trimToEmpty(context.getBidPrices(key)).entrySet().stream()
            .filter(e -> e.getValue() != null)
            .filter(e -> e.getKey() != null)
            .filter(e -> e.getKey().compareTo(floor) >= 0)
            .forEach(e -> {
                averages[I_NOTIONAL] = averages[I_NOTIONAL] + e.getValue().doubleValue() * e.getKey().doubleValue();
                averages[I_QUANTITY] = averages[I_QUANTITY] + e.getValue().doubleValue();
                averages[I_SIZE_BID] = averages[I_SIZE_BID] + e.getValue().doubleValue();
            });

    double average = averages[I_NOTIONAL] / averages[I_QUANTITY];

    if (!Double.isFinite(average)) {
        return BAIL;
    }

    BigDecimal d = valueOf(average).subtract(mid);

    BigDecimal p = mid.subtract(d);

    BigDecimal c = ONE.subtract(deviation).min(ONE).max(ZERO).multiply(HALF);

    log.debug("Estimated : {} (confidence=[{}] mid=[{}] dev=[{}] avg=[{}] askVol=[{}] bidVol=[{}])",
            p, c, mid, deviation, average, averages[I_SIZE_ASK], averages[I_SIZE_BID]);

    return Estimation.builder().price(p).confidence(c).build();

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

示例15: isRound

import java.math.BigDecimal; //导入方法依赖的package包/类
public static boolean isRound(BigDecimal num, int precision) {
    return num.signum() == 0 || num.scale() <= 0 || round(num, 0).compareTo(round(num, precision)) == 0;
}
 
开发者ID:Baizey,项目名称:Helpers,代码行数:4,代码来源:Numbers.java


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