Esempio n. 1
0
    private bool CheckIsBigger(CSLargeInt otherNum)
    {
        List <int> lstOther = otherNum.m_lstNum;

        if (lstOther.Count > m_lstNum.Count)
        {
            return(true);
        }
        if (lstOther.Count < m_lstNum.Count)
        {
            return(false);
        }
        for (int i = m_lstNum.Count - 1; i > 0; i--)
        {
            if (lstOther[i] > m_lstNum[i])
            {
                return(true);
            }
            if (lstOther[i] < m_lstNum[i])
            {
                return(false);
            }
        }
        return(true);
    }
Esempio n. 2
0
    public static CSLargeInt MultiUp(CSLargeInt baseNum, float fInc, int uAddLevel, int uGiveNum = 0, CSLargeInt targetNB = null)
    {
        if (fInc < 1 && uGiveNum > 0)
        {
            Debug.LogError("MultiUp ERROR");
        }
        CSLargeInt nb       = new CSLargeInt(baseNum);
        List <int> lstNbNum = nb.m_lstNum;
        int        uInc     = (int)(fInc * THOUSAND);

        for (int i = 0; i < uAddLevel; i++)
        {
            if (targetNB != null)
            {
                SAdd(targetNB.m_lstNum, lstNbNum);
            }
            lstNbNum[1] += uGiveNum;
            SMultiply(lstNbNum, uInc);
            lstNbNum.RemoveAt(0);
            if (uGiveNum > 0)
            {
                SSubtraction(lstNbNum, uGiveNum);
            }
        }
        nb.Trim();
        return(nb);
    }
Esempio n. 3
0
    private CSLargeInt Multiply(int otherNum)
    {
        CSLargeInt nb = new CSLargeInt(this);

        SMultiply(nb.m_lstNum, otherNum);
        nb.Trim();
        return(nb);
    }
Esempio n. 4
0
    public static CSLargeInt operator *(float fNum, CSLargeInt r)
    {
        CSLargeInt nb = r.Multiply((int)(fNum * THOUSAND));

        nb.m_lstNum.RemoveAt(0);
        nb.NoEmpty();
        return(nb);
    }
Esempio n. 5
0
    public static CSLargeInt operator +(CSLargeInt l, CSLargeInt r)
    {
        CSLargeInt nb       = new CSLargeInt(l);
        List <int> lstNbNum = nb.m_lstNum;
        List <int> lstRight = r.m_lstNum;

        SAdd(lstNbNum, lstRight);
        return(nb);
    }
Esempio n. 6
0
    public static CSLargeInt MultiUpB(CSLargeInt baseNum, int uAddLevel, CSLargeInt targetNB, CalculateDelegate func)
    {
        CSLargeInt nb       = new CSLargeInt(baseNum);
        List <int> lstNbNum = nb.m_lstNum;

        for (int i = 0; i < uAddLevel; i++)
        {
            int uInc = (int)(func(i + 1) * THOUSAND);
            SAdd(targetNB.m_lstNum, lstNbNum);
            SMultiply(lstNbNum, uInc);
            lstNbNum.RemoveAt(0);
        }
        nb.Trim();
        return(nb);
    }
Esempio n. 7
0
    public static CSLargeInt operator -(CSLargeInt l, CSLargeInt r)
    {
        if (!r.CheckIsBigger(l))
        {
            Debug.LogError("NumberBase operator - :" + l + "-" + r);
        }
        CSLargeInt nb       = new CSLargeInt();
        List <int> lstNbNum = nb.m_lstNum;
        List <int> lstLeft  = l.m_lstNum;
        List <int> lstRight = r.m_lstNum;

        lstNbNum[0] = lstLeft[0];
        int uBorr = 0;

        for (int i = 1; i < lstLeft.Count; i++)
        {
            if (i >= lstRight.Count)
            {
                if (lstLeft[i] < uBorr)
                {
                    lstNbNum.Add(lstLeft[i] + THOUSAND - uBorr);
                    uBorr = 1;
                }
                else
                {
                    lstNbNum.Add(lstLeft[i] - uBorr);
                    uBorr = 0;
                }
            }
            else
            {
                if (lstLeft[i] < lstRight[i] + uBorr)
                {
                    lstNbNum.Add(lstLeft[i] + THOUSAND - lstRight[i] - uBorr);
                    uBorr = 1;
                }
                else
                {
                    lstNbNum.Add(lstLeft[i] - lstRight[i] - uBorr);
                    uBorr = 0;
                }
            }
        }
        nb.Trim();
        return(nb);
    }
Esempio n. 8
0
 public CSLargeInt(CSLargeInt copyNum)
 {
     m_lstNum = new List <int>(copyNum.m_lstNum.ToArray());
 }