Package java.math

Examples of java.math.BigDecimal.signum()


     * @return Node:Decimal
     * @throws Exception
     */
    public Node external_truncate(Node startAt) throws Exception {
        BigDecimal num = number.get();
        boolean negatif = num.signum()==-1;
        BigDecimal n=num.abs();
        BigDecimal n2 = BigDecimalMath.floor(n);
        n = negatif ? n2.negate(): n2;
        return Node.createExternal(new External_Decimal(n,context.get()));
    }
View Full Code Here


     *
     * @return BigInteger
     */
    public BigInteger toInteger(){
        BigDecimal num = number.get();
        boolean negatif = num.signum()==-1;
        BigDecimal n=num.abs();
        BigInteger n2 = BigDecimalMath.round(n).toBigInteger();
        return negatif ? n2.negate(): n2;
    }
   
View Full Code Here

                throw new InvalidDatatypeValueException(msg);
            }
        }
        if ((fFacetsDefined & DatatypeValidator.FACET_TOTALDIGITS)!=0) {
            int totalDigits = d.movePointRight(d.scale()).toString().length() -
                              ((d.signum() < 0) ? 1 : 0); // account for minus sign
            if (totalDigits > fTotalDigits) {

                String msg = getErrorString(
                                           DatatypeMessageProvider.fgMessageKeys[DatatypeMessageProvider.TOTALDIGITS_EXCEEDED],
                                           new Object[] {
View Full Code Here

                if (isOverflowExceptionMode(runtime)) {
                    throw runtime.newFloatDomainError("exponent overflow");
                }
                decimal = new BigDecimal(0);
            }
            if (decimal.signum() == 0) {
                // MRI behavior: -0 and +0 are two different things
                if (strValue.matches("^\\s*-.*")) {
                    return newZero(runtime, -1);
                } else {
                    return newZero(runtime, 1);
View Full Code Here

            return newNaN(runtime);
        }

        // Java and MRI definitions of modulo are different.
        BigDecimal modulo = value.remainder(val.value);
        if (modulo.signum() * val.value.signum() < 0) {
            modulo = modulo.add(val.value);
        }

        return new RubyBigDecimal(runtime, modulo).setResult();
    }
View Full Code Here

        BigDecimal[] divmod = value.divideAndRemainder(val.value);

        BigDecimal div = divmod[0];
        BigDecimal mod = divmod[1];

        if (mod.signum() * val.value.signum() < 0) {
            div = div.subtract(BigDecimal.ONE);
            mod = mod.add(val.value);
        }

        return RubyArray.newArray(runtime,
View Full Code Here

     */
    public DecimalValue divide(DurationValue other) throws XPathException {
        if (other instanceof DayTimeDurationValue) {
            BigDecimal v1 = BigDecimal.valueOf(getLengthInMicroseconds());
            BigDecimal v2 = BigDecimal.valueOf(((DayTimeDurationValue)other).getLengthInMicroseconds());
            if (v2.signum() == 0) {
                XPathException err = new XPathException("Divide by zero (durations)");
                err.setErrorCode("FOAR0001");
                throw err;
            }
            return new DecimalValue(v1.divide(v2, 20, BigDecimal.ROUND_HALF_EVEN));
View Full Code Here

                return ((IntegerValue)a).idiv((IntegerValue)b);
            }

            final BigDecimal A = ((NumericValue)a).getDecimalValue();
            final BigDecimal B = ((NumericValue)b).getDecimalValue();
            if (B.signum() == 0) {
                throw new XPathException("Integer division by zero", "FOAR0001", c);
            }
            BigInteger quot = A.divide(B, 0, BigDecimal.ROUND_DOWN).toBigInteger();
            return BigIntegerValue.makeIntegerValue(quot);
        }
View Full Code Here

    public DecimalValue divide(DurationValue other) throws XPathException {
        if (other instanceof YearMonthDurationValue) {
            BigDecimal v1 = BigDecimal.valueOf(getLengthInMonths());
            BigDecimal v2 = BigDecimal.valueOf(((YearMonthDurationValue)other).getLengthInMonths());
            if (v2.signum() == 0) {
                XPathException err = new XPathException("Divide by zero (durations)");
                err.setErrorCode("FOAR0001");
                throw err;
            }
            return new DecimalValue(v1.divide(v2, 20, BigDecimal.ROUND_HALF_EVEN));
View Full Code Here

    public static boolean hasDecimal (BigDecimal amount)
    {
        BigDecimal absVal = amount.abs();
        BigDecimal wholeValue = new BigDecimal(absVal.toBigInteger());
        BigDecimal decimalValue = absVal.subtract(wholeValue);
        return decimalValue.signum() > 0;
    }

    /**
        Returns the number of digits in the decimal part of the number.
        @param bd The BigDecimal input
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.