示例#1
0
        public static List <int> DeCateOriIntra(List <int> b, List <int> temp)
        {
            if (Floatz.ListIsZero(temp))
            {
                return new List <int> {
                           0
                }
            }
            ;
            temp = Floatz.ComprimaList(temp, "intreaga");
            if (Floatz.Compare2Lists(temp, b) == 1)
            {
                return new List <int> {
                           0
                }
            }
            ;
            if (Floatz.Compare2Lists(temp, b) == 0)
            {
                return new List <int> {
                           1
                }
            }
            ;


            List <int> _b = new List <int>();

            foreach (int item in b)
            {
                _b.Add(item);
            }

            List <int> i = new List <int> {
                0
            };
            int cmp = Floatz.Compare2Lists(temp, _b);

            while (cmp == -1)
            {
                i = Floatz.Add2Lists(i, new List <int> {
                    1
                });
                _b.Clear();
                _b  = Floatz.Multiply2Lists(b, i);
                cmp = Floatz.Compare2Lists(temp, _b);
            }
            if (cmp != 0)
            {
                i = Floatz.Subtract2Lists(i, new List <int> {
                    1
                });
            }
            i = ComprimaList(i);
            return(i);
        }
示例#2
0
        public static Floatz DivideFloatzWithList(Floatz a, List <int> b, long nrMaxZecimalaLaImpartire, bool debugMode = false)
        {
            Floatz     c    = new Floatz();
            List <int> temp = new List <int>();
            int        cmp  = 0;

            for (int i = 0; i < a.intreaga.Count; i++)
            {
                temp.Add(a.intreaga[i]);
                cmp = Compare2Lists(temp, b);
                if (cmp < 1)//317/51 || 317 || 51
                {
                    List <int> deCateOriIntra = DeCateOriIntra(b, temp);
                    List <int> sub            = Floatz.Multiply2Lists(deCateOriIntra, b);
                    if (debugMode)
                    {
                        Console.WriteLine(Floatz.ListToString(temp) + "/" + Floatz.ListToString(b) + "=" + Floatz.ListToString(deCateOriIntra));
                    }

                    c.intreaga.AddRange(deCateOriIntra);
                    if (debugMode)
                    {
                        Console.Write(Floatz.ListToString(temp) + "-" + Floatz.ListToString(sub) + "=");
                    }
                    temp = Floatz.Subtract2Lists(temp, sub);
                    if (debugMode)
                    {
                        Console.Write(Floatz.ListToString(temp));
                        Console.WriteLine();
                    }

                    if (Floatz.ListIsZero(temp))
                    {
                        break;
                    }
                }
                else
                {
                    c.intreaga.Add(0);
                }
            }
            c.ComprimaIntreaga();
            if (nrMaxZecimalaLaImpartire == 0)
            {
                return(c);
            }
            c.zecimala.Clear();
            if (Floatz.ListIsZero(temp))
            {
                temp.Clear();
            }
            if (debugMode)
            {
                Console.WriteLine(",");
            }

            for (int i = 0; i < a.zecimala.Count && nrMaxZecimalaLaImpartire >= 0; i++)
            {
                temp.Add(a.zecimala[i]);

                cmp = Compare2Lists(temp, b);
                if (cmp < 1)
                {
                    List <int> deCateOriIntra = DeCateOriIntra(b, temp);
                    List <int> sub            = Floatz.Multiply2Lists(deCateOriIntra, b);
                    if (debugMode)
                    {
                        Console.WriteLine(Floatz.ListToString(temp) + "/" + Floatz.ListToString(b) + "=" + Floatz.ListToString(deCateOriIntra));
                    }

                    c.zecimala.AddRange(deCateOriIntra.GetRange(0, Math.Min(deCateOriIntra.Count, (int)nrMaxZecimalaLaImpartire)));
                    nrMaxZecimalaLaImpartire -= Math.Min(deCateOriIntra.Count, (int)nrMaxZecimalaLaImpartire);
                    if (debugMode)
                    {
                        Console.WriteLine("nrMaxZecimalaLaImpartire:" + nrMaxZecimalaLaImpartire);
                        Console.Write(Floatz.ListToString(temp) + "-" + Floatz.ListToString(sub) + "=");
                    }

                    temp = Floatz.Subtract2Lists(temp, sub);
                    cmp  = Compare2Lists(temp, b);
                    if (cmp == 1)
                    {
                        temp.Add(0);
                    }
                    if (debugMode)
                    {
                        Console.Write(Floatz.ListToString(temp));
                        Console.WriteLine();
                    }
                }
                else
                {
                    c.zecimala.Add(0);
                    nrMaxZecimalaLaImpartire--;
                }
            }
            if (!Floatz.ListIsZero(temp))
            {
                if (debugMode)
                {
                    Console.WriteLine("---start restu---");
                }
                if (nrMaxZecimalaLaImpartire > 0)
                {
                    if (cmp == 1)
                    {
                        temp.Add(0);
                    }
                    while (nrMaxZecimalaLaImpartire >= 0)//for (long i = nrMaxZecimalaLaImpartire; i >= 0; i--)
                    {
                        if (debugMode)
                        {
                            Console.WriteLine(Floatz.ListToString(temp));
                        }
                        cmp = Compare2Lists(temp, b);
                        if (debugMode)
                        {
                            Console.WriteLine(Floatz.ListToString(temp) + "?" + Floatz.ListToString(b) + "=" + cmp);
                        }
                        if (cmp < 1)
                        {
                            List <int> deCateOriIntra = DeCateOriIntra(b, temp);
                            List <int> sub            = Floatz.Multiply2Lists(deCateOriIntra, b);
                            if (debugMode)
                            {
                                Console.WriteLine(Floatz.ListToString(temp) + "/" + Floatz.ListToString(b) + "=" + Floatz.ListToString(deCateOriIntra));
                            }

                            c.zecimala.AddRange(deCateOriIntra.GetRange(0, Math.Min(deCateOriIntra.Count, (int)nrMaxZecimalaLaImpartire)));
                            nrMaxZecimalaLaImpartire -= Math.Min(deCateOriIntra.Count, (int)nrMaxZecimalaLaImpartire);
                            if (nrMaxZecimalaLaImpartire == 0)
                            {
                                break;
                            }
                            if (debugMode)
                            {
                                Console.Write(Floatz.ListToString(temp) + "-" + Floatz.ListToString(sub) + "=");
                            }
                            temp = Floatz.Subtract2Lists(temp, sub);
                            cmp  = Compare2Lists(temp, b);
                            if (cmp == 1)
                            {
                                temp.Add(0);
                            }
                            if (debugMode)
                            {
                                Console.Write(Floatz.ListToString(temp));
                                Console.WriteLine();
                            }
                            if (Floatz.ListIsZero(temp))
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (debugMode)
                            {
                                Console.WriteLine("0 was added.");
                            }
                            c.zecimala.Add(0);
                            temp.Add(0);
                            nrMaxZecimalaLaImpartire--;
                        }
                    }
                }
            }
            if (debugMode)
            {
                Console.WriteLine(".");
            }
            c.ComprimaZecimala();
            return(c);
        }