private void Sub(BigUInt <N> v)
 {
     for (int dig = 0; dig < Length; dig++)
     {
         CarrySub(dig, v[dig]);
     }
 }
        public static BigUInt <N> Add(BigUInt <N> v1, BigUInt <N> v2)
        {
            BigUInt <N> ret = v1.Copy();

            ret.Add(v2);

            return(ret);
        }
        public static BigUInt <N> Sub(BigUInt <N> v1, BigUInt <N> v2)
        {
            BigUInt <N> ret = v1.Copy();

            ret.Sub(v2);

            return(ret);
        }
        public static BigUInt <N> Add(BigUInt <N> v1, UInt32 v2)
        {
            BigUInt <N> ret = v1.Copy();

            ret.CarryAdd(0, v2);

            return(ret);
        }
Пример #5
0
        public static BigUInt <N> RightBlockShift(BigUInt <N> n, int sft)
        {
            BigUInt <N> ret = n.Copy();

            ret.RightBlockShift(sft);

            return(ret);
        }
Пример #6
0
        public static BigUInt <N> LeftShift(BigUInt <N> n, int sft)
        {
            BigUInt <N> ret = n.Copy();

            ret.LeftShift(sft);

            return(ret);
        }
Пример #7
0
        public static Mantissa <N> Decimal(int digits)
        {
            if (!Consts.decimals.ContainsKey(digits))
            {
                Consts.decimals.Add(digits, new Mantissa <N>(BigUInt <N> .Decimal(digits)));
            }

            return(Consts.decimals[digits]);
        }
Пример #8
0
        public static Accumulator <N> Decimal(int digits)
        {
            if (!Consts.decimals.ContainsKey(digits))
            {
                Consts.decimals.Add(digits, new Accumulator <N>(BigUInt <Double <N> > .Decimal(digits)));
            }

            return(Consts.decimals[digits]);
        }
        public static BigUInt <N> Mul(BigUInt <N> v1, BigUInt <N> v2)
        {
            BigUInt <Double <N> > v = ExpandMul(v1, v2);

            if (v.Digits > Length)
            {
                throw new OverflowException();
            }

            return(new BigUInt <N>(v.value[..Length], enable_clone: false));
Пример #10
0
        public static BigUInt <N> RightRoundBlockShift(BigUInt <N> n, int sft)
        {
            BigUInt <N> ret = n.Copy();

            ret.RightBlockShift(sft);

            if (sft >= 1 && sft <= Length && n.value[sft - 1] > UIntUtil.UInt32Round)
            {
                ret.CarryAdd(0, 1);
            }

            return(ret);
        }
Пример #11
0
        public static BigUInt <N> RightRoundShift(BigUInt <N> n, int sft)
        {
            BigUInt <N> ret = n.Copy();

            ret.RightShift(sft);

            if (sft >= 1 && sft <= Bits && UIntUtil.GetLSB(n.value, sft - 1) != 0)
            {
                ret.CarryAdd(0, 1);
            }

            return(ret);
        }
Пример #12
0
 public Accumulator(Mantissa <N> n, Int64 sft = 0)
 {
     if (sft == 0)
     {
         this.value = new BigUInt <Double <N> >(n.Value, 0);
     }
     else if (sft > 0)
     {
         this.value = new BigUInt <Double <N> >(n.Value, 0) << checked ((int)sft);
     }
     else if (sft < 0 && sft > -Bits)
     {
         this.value = new BigUInt <Double <N> >(n.Value, 0) >> (int)-sft;
     }
     else
     {
         this.value = BigUInt <Double <N> > .Zero;
     }
 }
Пример #13
0
        public int CompareTo([AllowNull] BigUInt <N> other)
        {
            if (other is null)
            {
                return(1);
            }

            if (this < other)
            {
                return(-1);
            }

            if (this == other)
            {
                return(0);
            }

            return(1);
        }
Пример #14
0
        private static BigUInt <N> GenerateDecimal(int digits)
        {
            if (digits < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(digits));
            }

            UInt64 v = 1;

            for (int i = 0; i < digits % UIntUtil.UInt64MaxDecimalDigits; i++)
            {
                v *= 10;
            }

            BigUInt <N> uint64_maxdec = UIntUtil.UInt64MaxDecimal;
            BigUInt <N> biguint_dec   = v;

            for (int i = 0; i < digits / UIntUtil.UInt64MaxDecimalDigits; i++)
            {
                biguint_dec *= uint64_maxdec;
            }

            return(biguint_dec);
        }
Пример #15
0
 public Accumulator()
 {
     this.value = new BigUInt <Double <N> >();
 }
 public static Accumulator <N> Mul(Accumulator <N> v1, Accumulator <N> v2)
 {
     return(new Accumulator <N>(BigUInt <Double <N> > .Mul(v1.value, v2.value)));
 }
        public static (Accumulator <N> div, Accumulator <N> rem) Div(Accumulator <N> v1, Accumulator <N> v2)
        {
            (BigUInt <Double <N> > div, BigUInt <Double <N> > rem) = BigUInt <Double <N> > .Div(v1.value, v2.value);

            return(new Accumulator <N>(div), new Accumulator <N>(rem));
        }
Пример #18
0
 public Accumulator(BigUInt <Double <N> > value)
 {
     this.value = value;
 }
Пример #19
0
 public Accumulator(ReadOnlyCollection <UInt32> arr)
 {
     this.value = new BigUInt <Double <N> >(arr);
 }
Пример #20
0
 public static int MatchBits(Mantissa <N> a, Mantissa <N> b)
 {
     return(BigUInt <N> .MatchBits(a.value, b.value));
 }
        public static Accumulator <N> MulShift(Accumulator <N> v1, Accumulator <N> v2)
        {
            Accumulator <N> v = new(BigUInt <Double <N> > .Mul(v1.value, v2.value));

            return(RightRoundShift(v, Mantissa <N> .Bits - 1));
        }
 public static Mantissa <N> RoundDiv(Mantissa <N> v1, Mantissa <N> v2)
 {
     return(new Mantissa <N>(BigUInt <N> .RoundDiv(v1.value, v2.value)));
 }
        public static (Mantissa <N> div, Mantissa <N> rem) Div(Mantissa <N> v1, Mantissa <N> v2)
        {
            (BigUInt <N> div, BigUInt <N> rem) = BigUInt <N> .Div(v1.value, v2.value);

            return(new Mantissa <N>(div), new Mantissa <N>(rem));
        }
 public static Accumulator <N> Mul(Mantissa <N> v1, Mantissa <N> v2)
 {
     return(new Accumulator <N>(BigUInt <N> .ExpandMul(v1.value, v2.value)));
 }
 public static Mantissa <N> Sub(Mantissa <N> v1, UInt32 v2)
 {
     return(new Mantissa <N>(BigUInt <N> .Sub(v1.value, v2)));
 }
 public static Mantissa <N> Add(Mantissa <N> v1, Mantissa <N> v2)
 {
     return(new Mantissa <N>(BigUInt <N> .Add(v1.value, v2.value)));
 }
Пример #27
0
 public Accumulator(UInt64 v) : this()
 {
     this.value = new BigUInt <Double <N> >(v);
 }
Пример #28
0
 public Accumulator(UInt32[] arr, bool enable_clone)
 {
     this.value = new BigUInt <Double <N> >(arr, enable_clone);
 }
Пример #29
0
 public static int MatchBits(BigUInt <N> a, BigUInt <N> b)
 {
     return(UIntUtil.MatchBits(Length, a.value, b.value));
 }
 public static Accumulator <N> RoundDiv(Accumulator <N> v1, Accumulator <N> v2)
 {
     return(new Accumulator <N>(BigUInt <Double <N> > .RoundDiv(v1.value, v2.value)));
 }