Ejemplo n.º 1
0
        public BigComplex Sqrt(MathContext mc)
        {
            BigDecimal half = new BigDecimal(2);

            /* compute l=sqrt(re^2+im^2), then u=sqrt((l+re)/2)
             * and v= +- sqrt((l-re)/2 as the new real and imaginary parts.
             */
            BigDecimal l = Abs(mc);

            if (l.CompareTo(BigDecimal.Zero) == 0)
            {
                return(new BigComplex(BigMath.ScalePrecision(BigDecimal.Zero, mc),
                                      BigMath.ScalePrecision(BigDecimal.Zero, mc)));
            }
            BigDecimal u = BigMath.Sqrt(l.Add(Real).Divide(half, mc), mc);
            BigDecimal v = BigMath.Sqrt(l.Subtract(Real).Divide(half, mc), mc);

            if (Imaginary.CompareTo(BigDecimal.Zero) >= 0)
            {
                return(new BigComplex(u, v));
            }
            else
            {
                return(new BigComplex(u, v.Negate()));
            }
        }
        public void CompareToBigDecimal()
        {
            BigDecimal comp1 = BigDecimal.Parse("1.00");
            BigDecimal comp2 = new BigDecimal(1.000000D);

            Assert.IsTrue(comp1.CompareTo(comp2) == 0, "1.00 and 1.000000 should be equal");
            BigDecimal comp3 = BigDecimal.Parse("1.02");

            Assert.IsTrue(comp3.CompareTo(comp1) == 1, "1.02 should be bigger than 1.00");
            BigDecimal comp4 = new BigDecimal(0.98D);

            Assert.IsTrue(comp4.CompareTo(comp1) == -1, "0.98 should be less than 1.00");
        }
Ejemplo n.º 3
0
        /**
         * Returns the maximum of this {@code BigDecimal} and {@code val}.
         *
         * @param val
         *            value to be used to compute the maximum with this.
         * @return {@code max(this, val}.
         * @throws NullPointerException
         *             if {@code val == null}.
         */

        public static BigDecimal Max(BigDecimal a, BigDecimal val)
        {
            return((a.CompareTo(val) >= 0) ? a : val);
        }