Exemple #1
0
 public SimpleBigDecimal Subtract(SimpleBigDecimal b)
 {
     return(Add(b.Negate()));
 }
Exemple #2
0
 private SimpleBigDecimal(SimpleBigDecimal limBigDec)
 {
     this.bigInt = limBigDec.bigInt;
     this.scale  = limBigDec.scale;
 }
Exemple #3
0
 public SimpleBigDecimal Add(SimpleBigDecimal b)
 {
     this.CheckScale(b);
     return(new SimpleBigDecimal(this.bigInt.Add(b.bigInt), this.scale));
 }
 private SimpleBigDecimal(SimpleBigDecimal limBigDec)
 {
     bigInt = limBigDec.bigInt;
     scale = limBigDec.scale;
 }
Exemple #5
0
        public static ZTauElement Round(SimpleBigDecimal lambda0, SimpleBigDecimal lambda1, sbyte mu)
        {
            SimpleBigDecimal num7;
            SimpleBigDecimal num8;
            int scale = lambda0.Scale;

            if (lambda1.Scale != scale)
            {
                throw new ArgumentException("lambda0 and lambda1 do not have same scale");
            }
            if ((mu != 1) && (mu != -1))
            {
                throw new ArgumentException("mu must be 1 or -1");
            }
            BigInteger       b        = lambda0.Round();
            BigInteger       integer2 = lambda1.Round();
            SimpleBigDecimal num2     = lambda0.Subtract(b);
            SimpleBigDecimal num3     = lambda1.Subtract(integer2);
            SimpleBigDecimal num4     = num2.Add(num2);

            if (mu == 1)
            {
                num4 = num4.Add(num3);
            }
            else
            {
                num4 = num4.Subtract(num3);
            }
            SimpleBigDecimal num5 = num3.Add(num3).Add(num3);
            SimpleBigDecimal num6 = num5.Add(num3);

            if (mu == 1)
            {
                num7 = num2.Subtract(num5);
                num8 = num2.Add(num6);
            }
            else
            {
                num7 = num2.Add(num5);
                num8 = num2.Subtract(num6);
            }
            sbyte num9  = 0;
            sbyte num10 = 0;

            if (num4.CompareTo(BigInteger.One) >= 0)
            {
                if (num7.CompareTo(MinusOne) < 0)
                {
                    num10 = mu;
                }
                else
                {
                    num9 = 1;
                }
            }
            else if (num8.CompareTo(BigInteger.Two) >= 0)
            {
                num10 = mu;
            }
            if (num4.CompareTo(MinusOne) < 0)
            {
                if (num7.CompareTo(BigInteger.One) >= 0)
                {
                    num10 = (sbyte)-((int)mu);
                }
                else
                {
                    num9 = -1;
                }
            }
            else if (num8.CompareTo(MinusTwo) < 0)
            {
                num10 = (sbyte)-((int)mu);
            }
            BigInteger u = b.Add(BigInteger.ValueOf((long)num9));

            return(new ZTauElement(u, integer2.Add(BigInteger.ValueOf((long)num10))));
        }
 public SimpleBigDecimal Multiply(SimpleBigDecimal b)
 {
     CheckScale(b);
     return new SimpleBigDecimal(bigInt.Multiply(b.bigInt), scale + scale);
 }
 public SimpleBigDecimal Subtract(SimpleBigDecimal b)
 {
     return Add(b.Negate());
 }
 public SimpleBigDecimal Multiply(SimpleBigDecimal b)
 {
     CheckScale(b);
     return(new SimpleBigDecimal(bigInt.Multiply(b.bigInt), scale + scale));
 }
        public BigInteger Round()
        {
            SimpleBigDecimal oneHalf = new SimpleBigDecimal(BigInteger.One, 1);

            return(Add(oneHalf.AdjustScale(scale)).Floor());
        }
Exemple #10
0
        public static ZTauElement Round(SimpleBigDecimal lambda0, SimpleBigDecimal lambda1, sbyte mu)
        {
            int scale = lambda0.Scale;

            if (lambda1.Scale != scale)
            {
                throw new ArgumentException("lambda0 and lambda1 do not have same scale");
            }
            if (mu != 1 && mu != -1)
            {
                throw new ArgumentException("mu must be 1 or -1");
            }
            BigInteger       bigInteger        = lambda0.Round();
            BigInteger       bigInteger2       = lambda1.Round();
            SimpleBigDecimal simpleBigDecimal  = lambda0.Subtract(bigInteger);
            SimpleBigDecimal simpleBigDecimal2 = lambda1.Subtract(bigInteger2);
            SimpleBigDecimal simpleBigDecimal3 = simpleBigDecimal.Add(simpleBigDecimal);

            if (mu == 1)
            {
                simpleBigDecimal3 = simpleBigDecimal3.Add(simpleBigDecimal2);
            }
            else
            {
                simpleBigDecimal3 = simpleBigDecimal3.Subtract(simpleBigDecimal2);
            }
            SimpleBigDecimal simpleBigDecimal4 = simpleBigDecimal2.Add(simpleBigDecimal2).Add(simpleBigDecimal2);
            SimpleBigDecimal b = simpleBigDecimal4.Add(simpleBigDecimal2);
            SimpleBigDecimal simpleBigDecimal5;
            SimpleBigDecimal simpleBigDecimal6;

            if (mu == 1)
            {
                simpleBigDecimal5 = simpleBigDecimal.Subtract(simpleBigDecimal4);
                simpleBigDecimal6 = simpleBigDecimal.Add(b);
            }
            else
            {
                simpleBigDecimal5 = simpleBigDecimal.Add(simpleBigDecimal4);
                simpleBigDecimal6 = simpleBigDecimal.Subtract(b);
            }
            sbyte b2 = 0;
            sbyte b3 = 0;

            if (simpleBigDecimal3.CompareTo(BigInteger.One) >= 0)
            {
                if (simpleBigDecimal5.CompareTo(Tnaf.MinusOne) < 0)
                {
                    b3 = mu;
                }
                else
                {
                    b2 = 1;
                }
            }
            else if (simpleBigDecimal6.CompareTo(BigInteger.Two) >= 0)
            {
                b3 = mu;
            }
            if (simpleBigDecimal3.CompareTo(Tnaf.MinusOne) < 0)
            {
                if (simpleBigDecimal5.CompareTo(BigInteger.One) >= 0)
                {
                    b3 = -mu;
                }
                else
                {
                    b2 = -1;
                }
            }
            else if (simpleBigDecimal6.CompareTo(Tnaf.MinusTwo) < 0)
            {
                b3 = -mu;
            }
            BigInteger u = bigInteger.Add(BigInteger.ValueOf((long)b2));
            BigInteger v = bigInteger2.Add(BigInteger.ValueOf((long)b3));

            return(new ZTauElement(u, v));
        }
 public SimpleBigDecimal Add(SimpleBigDecimal b)
 {
     CheckScale(b);
     return(new SimpleBigDecimal(bigInt.Add(b.bigInt), scale));
 }
        /**
        * Rounds an element <code>&#955;</code> of <code><b>R</b>[&#964;]</code>
        * to an element of <code><b>Z</b>[&#964;]</code>, such that their difference
        * has minimal norm. <code>&#955;</code> is given as
        * <code>&#955; = &#955;<sub>0</sub> + &#955;<sub>1</sub>&#964;</code>.
        * @param lambda0 The component <code>&#955;<sub>0</sub></code>.
        * @param lambda1 The component <code>&#955;<sub>1</sub></code>.
        * @param mu The parameter <code>&#956;</code> of the elliptic curve. Must
        * equal 1 or -1.
        * @return The rounded element of <code><b>Z</b>[&#964;]</code>.
        * @throws ArgumentException if <code>lambda0</code> and
        * <code>lambda1</code> do not have same scale.
        */
        public static ZTauElement Round(SimpleBigDecimal lambda0,
			SimpleBigDecimal lambda1, sbyte mu)
        {
            int scale = lambda0.Scale;
            if (lambda1.Scale != scale)
                throw new ArgumentException("lambda0 and lambda1 do not have same scale");

            if (!((mu == 1) || (mu == -1)))
                throw new ArgumentException("mu must be 1 or -1");

            IBigInteger f0 = lambda0.Round();
            IBigInteger f1 = lambda1.Round();

            SimpleBigDecimal eta0 = lambda0.Subtract(f0);
            SimpleBigDecimal eta1 = lambda1.Subtract(f1);

            // eta = 2*eta0 + mu*eta1
            SimpleBigDecimal eta = eta0.Add(eta0);
            if (mu == 1)
            {
                eta = eta.Add(eta1);
            }
            else
            {
                // mu == -1
                eta = eta.Subtract(eta1);
            }

            // check1 = eta0 - 3*mu*eta1
            // check2 = eta0 + 4*mu*eta1
            SimpleBigDecimal threeEta1 = eta1.Add(eta1).Add(eta1);
            SimpleBigDecimal fourEta1 = threeEta1.Add(eta1);
            SimpleBigDecimal check1;
            SimpleBigDecimal check2;
            if (mu == 1)
            {
                check1 = eta0.Subtract(threeEta1);
                check2 = eta0.Add(fourEta1);
            }
            else
            {
                // mu == -1
                check1 = eta0.Add(threeEta1);
                check2 = eta0.Subtract(fourEta1);
            }

            sbyte h0 = 0;
            sbyte h1 = 0;

            // if eta >= 1
            if (eta.CompareTo(BigInteger.One) >= 0)
            {
                if (check1.CompareTo(MinusOne) < 0)
                {
                    h1 = mu;
                }
                else
                {
                    h0 = 1;
                }
            }
            else
            {
                // eta < 1
                if (check2.CompareTo(BigInteger.Two) >= 0)
                {
                    h1 = mu;
                }
            }

            // if eta < -1
            if (eta.CompareTo(MinusOne) < 0)
            {
                if (check1.CompareTo(BigInteger.One) >= 0)
                {
                    h1 = (sbyte)-mu;
                }
                else
                {
                    h0 = -1;
                }
            }
            else
            {
                // eta >= -1
                if (check2.CompareTo(MinusTwo) < 0)
                {
                    h1 = (sbyte)-mu;
                }
            }

            IBigInteger q0 = f0.Add(BigInteger.ValueOf(h0));
            IBigInteger q1 = f1.Add(BigInteger.ValueOf(h1));
            return new ZTauElement(q0, q1);
        }
        /**
        * Computes the norm of an element <code>&#955;</code> of
        * <code><b>R</b>[&#964;]</code>, where <code>&#955; = u + v&#964;</code>
        * and <code>u</code> and <code>u</code> are real numbers (elements of
        * <code><b>R</b></code>).
        * @param mu The parameter <code>&#956;</code> of the elliptic curve.
        * @param u The real part of the element <code>&#955;</code> of
        * <code><b>R</b>[&#964;]</code>.
        * @param v The <code>&#964;</code>-adic part of the element
        * <code>&#955;</code> of <code><b>R</b>[&#964;]</code>.
        * @return The norm of <code>&#955;</code>.
        */
        public static SimpleBigDecimal Norm(sbyte mu, SimpleBigDecimal u, SimpleBigDecimal v)
        {
            SimpleBigDecimal norm;

            // s1 = u^2
            SimpleBigDecimal s1 = u.Multiply(u);

            // s2 = u * v
            SimpleBigDecimal s2 = u.Multiply(v);

            // s3 = 2 * v^2
            SimpleBigDecimal s3 = v.Multiply(v).ShiftLeft(1);

            if (mu == 1)
            {
                norm = s1.Add(s2).Add(s3);
            }
            else if (mu == -1)
            {
                norm = s1.Subtract(s2).Add(s3);
            }
            else
            {
                throw new ArgumentException("mu must be 1 or -1");
            }

            return norm;
        }
Exemple #14
0
        /**
         * Rounds an element <code>&#955;</code> of <code><b>R</b>[&#964;]</code>
         * to an element of <code><b>Z</b>[&#964;]</code>, such that their difference
         * has minimal norm. <code>&#955;</code> is given as
         * <code>&#955; = &#955;<sub>0</sub> + &#955;<sub>1</sub>&#964;</code>.
         * @param lambda0 The component <code>&#955;<sub>0</sub></code>.
         * @param lambda1 The component <code>&#955;<sub>1</sub></code>.
         * @param mu The parameter <code>&#956;</code> of the elliptic curve. Must
         * equal 1 or -1.
         * @return The rounded element of <code><b>Z</b>[&#964;]</code>.
         * @throws ArgumentException if <code>lambda0</code> and
         * <code>lambda1</code> do not have same scale.
         */
        public static ZTauElement Round(SimpleBigDecimal lambda0,
                                        SimpleBigDecimal lambda1, sbyte mu)
        {
            int scale = lambda0.Scale;

            if (lambda1.Scale != scale)
            {
                throw new ArgumentException("lambda0 and lambda1 do not have same scale");
            }

            if (!((mu == 1) || (mu == -1)))
            {
                throw new ArgumentException("mu must be 1 or -1");
            }

            BigInteger f0 = lambda0.Round();
            BigInteger f1 = lambda1.Round();

            SimpleBigDecimal eta0 = lambda0.Subtract(f0);
            SimpleBigDecimal eta1 = lambda1.Subtract(f1);

            // eta = 2*eta0 + mu*eta1
            SimpleBigDecimal eta = eta0.Add(eta0);

            if (mu == 1)
            {
                eta = eta.Add(eta1);
            }
            else
            {
                // mu == -1
                eta = eta.Subtract(eta1);
            }

            // check1 = eta0 - 3*mu*eta1
            // check2 = eta0 + 4*mu*eta1
            SimpleBigDecimal threeEta1 = eta1.Add(eta1).Add(eta1);
            SimpleBigDecimal fourEta1  = threeEta1.Add(eta1);
            SimpleBigDecimal check1;
            SimpleBigDecimal check2;

            if (mu == 1)
            {
                check1 = eta0.Subtract(threeEta1);
                check2 = eta0.Add(fourEta1);
            }
            else
            {
                // mu == -1
                check1 = eta0.Add(threeEta1);
                check2 = eta0.Subtract(fourEta1);
            }

            sbyte h0 = 0;
            sbyte h1 = 0;

            // if eta >= 1
            if (eta.CompareTo(BigInteger.One) >= 0)
            {
                if (check1.CompareTo(MinusOne) < 0)
                {
                    h1 = mu;
                }
                else
                {
                    h0 = 1;
                }
            }
            else
            {
                // eta < 1
                if (check2.CompareTo(BigInteger.Two) >= 0)
                {
                    h1 = mu;
                }
            }

            // if eta < -1
            if (eta.CompareTo(MinusOne) < 0)
            {
                if (check1.CompareTo(BigInteger.One) >= 0)
                {
                    h1 = (sbyte)-mu;
                }
                else
                {
                    h0 = -1;
                }
            }
            else
            {
                // eta >= -1
                if (check2.CompareTo(MinusTwo) < 0)
                {
                    h1 = (sbyte)-mu;
                }
            }

            BigInteger q0 = f0.Add(BigInteger.ValueOf(h0));
            BigInteger q1 = f1.Add(BigInteger.ValueOf(h1));

            return(new ZTauElement(q0, q1));
        }
 public int CompareTo(SimpleBigDecimal val)
 {
     CheckScale(val);
     return bigInt.CompareTo(val.bigInt);
 }
 private SimpleBigDecimal(SimpleBigDecimal limBigDec)
 {
     bigInt = limBigDec.bigInt;
     scale  = limBigDec.scale;
 }
 public SimpleBigDecimal Divide(SimpleBigDecimal b)
 {
     CheckScale(b);
     IBigInteger dividend = bigInt.ShiftLeft(scale);
     return new SimpleBigDecimal(dividend.Divide(b.bigInt), scale);
 }
Exemple #18
0
 public SimpleBigDecimal Multiply(SimpleBigDecimal b)
 {
     this.CheckScale(b);
     return(new SimpleBigDecimal(this.bigInt.Multiply(b.bigInt), this.scale + this.scale));
 }
 public IBigInteger Round()
 {
     SimpleBigDecimal oneHalf = new SimpleBigDecimal(BigInteger.One, 1);
     return Add(oneHalf.AdjustScale(scale)).Floor();
 }
Exemple #20
0
 public int CompareTo(SimpleBigDecimal val)
 {
     this.CheckScale(val);
     return(this.bigInt.CompareTo(val.bigInt));
 }
 private void CheckScale(SimpleBigDecimal b)
 {
     if (scale != b.scale)
         throw new ArgumentException("Only SimpleBigDecimal of same scale allowed in arithmetic operations");
 }
Exemple #22
0
        public BigInteger Round()
        {
            SimpleBigDecimal simpleBigDecimal = new SimpleBigDecimal(BigInteger.One, 1);

            return(this.Add(simpleBigDecimal.AdjustScale(this.scale)).Floor());
        }
 public SimpleBigDecimal Add(SimpleBigDecimal b)
 {
     CheckScale(b);
     return new SimpleBigDecimal(bigInt.Add(b.bigInt), scale);
 }
Exemple #24
0
        public static ZTauElement Round(SimpleBigDecimal lambda0, SimpleBigDecimal lambda1, sbyte mu)
        {
            //IL_0015: Unknown result type (might be due to invalid IL or missing references)
            //IL_0028: Unknown result type (might be due to invalid IL or missing references)
            int scale = lambda0.Scale;

            if (lambda1.Scale != scale)
            {
                throw new ArgumentException("lambda0 and lambda1 do not have same scale");
            }
            if (mu != 1 && mu != -1)
            {
                throw new ArgumentException("mu must be 1 or -1");
            }
            BigInteger       bigInteger        = lambda0.Round();
            BigInteger       bigInteger2       = lambda1.Round();
            SimpleBigDecimal simpleBigDecimal  = lambda0.Subtract(bigInteger);
            SimpleBigDecimal simpleBigDecimal2 = lambda1.Subtract(bigInteger2);
            SimpleBigDecimal simpleBigDecimal3 = simpleBigDecimal.Add(simpleBigDecimal);

            simpleBigDecimal3 = ((mu != 1) ? simpleBigDecimal3.Subtract(simpleBigDecimal2) : simpleBigDecimal3.Add(simpleBigDecimal2));
            SimpleBigDecimal simpleBigDecimal4 = simpleBigDecimal2.Add(simpleBigDecimal2).Add(simpleBigDecimal2);
            SimpleBigDecimal b = simpleBigDecimal4.Add(simpleBigDecimal2);
            SimpleBigDecimal simpleBigDecimal5;
            SimpleBigDecimal simpleBigDecimal6;

            if (mu == 1)
            {
                simpleBigDecimal5 = simpleBigDecimal.Subtract(simpleBigDecimal4);
                simpleBigDecimal6 = simpleBigDecimal.Add(b);
            }
            else
            {
                simpleBigDecimal5 = simpleBigDecimal.Add(simpleBigDecimal4);
                simpleBigDecimal6 = simpleBigDecimal.Subtract(b);
            }
            sbyte b2 = 0;
            sbyte b3 = 0;

            if (simpleBigDecimal3.CompareTo(BigInteger.One) >= 0)
            {
                if (simpleBigDecimal5.CompareTo(MinusOne) < 0)
                {
                    b3 = mu;
                }
                else
                {
                    b2 = 1;
                }
            }
            else if (simpleBigDecimal6.CompareTo(BigInteger.Two) >= 0)
            {
                b3 = mu;
            }
            if (simpleBigDecimal3.CompareTo(MinusOne) < 0)
            {
                if (simpleBigDecimal5.CompareTo(BigInteger.One) >= 0)
                {
                    b3 = (sbyte)(-mu);
                }
                else
                {
                    b2 = -1;
                }
            }
            else if (simpleBigDecimal6.CompareTo(MinusTwo) < 0)
            {
                b3 = (sbyte)(-mu);
            }
            BigInteger u = bigInteger.Add(BigInteger.ValueOf(b2));
            BigInteger v = bigInteger2.Add(BigInteger.ValueOf(b3));

            return(new ZTauElement(u, v));
        }