signum() public method

public signum ( ) : int
return int
示例#1
0
        /**
         * Calculates the multiplication (*) of this rational number and the specified argument.
         *
         * <p>This is functionally identical to
         * <code>this.multiply(BigRational.valueOf(value))</code>
         * but slightly faster.</p>
         *
         * <p>The result has no loss of precision.</p>
         *
         * @param value the {@link BigInteger} to multiply
         * @return the resulting rational number
         */
        public BigRational multiply(BigInteger value)
        {
            if (isZero() || value.signum() == 0)
            {
                return(ZERO);
            }
            if (equals(ONE))
            {
                return(valueOf(value));
            }
            if (value.equals(BigInteger.ONE))
            {
                return(this);
            }

            return(multiply(new BigDecimal(value)));
        }
示例#2
0
 public static object BIDivide(BigInteger n, BigInteger d)
 {
     if (d.Equals(BigIntegerZero))
         throw new ArithmeticException("Divide by zero");
     BigInteger gcd = n.gcd(d);
     if (gcd.Equals(BigIntegerZero))
         return 0;
     n = n.divide(gcd);
     d = d.divide(gcd);
     if (d.Equals(BigIntegerOne))
         return reduce(n);
     return new Ratio((d.signum() < 0 ? n.negate() : n),
         (d.signum() < 0 ? d.negate() : d));
 }