コード例 #1
0
        /// <summary>
        /// Returns aligned rightOperand relative to leftOperand.
        /// IMPORTANT: leftOperand must be greater or equal (>=) to rightOperand
        /// </summary>
        /// <param name="leftOperand">Operand, relative to which rightOperand will be aligned.</param>
        /// <param name="rightOperand">Operand, that will be aligned</param>
        /// <returns>Aligned operand.</returns>
        public static PBNumber ExponentAlign(PBNumber leftOperand, PBNumber rightOperand)
        {
            PBConvertion pbconvertion = new PBConvertion();
            int leftExponentValue = Int32.Parse(pbconvertion.convert2to10IPart(leftOperand.Exponent));
            int rightExponentValue = Int32.Parse(pbconvertion.convert2to10IPart(rightOperand.Exponent));

            return Shift(rightOperand, leftExponentValue - rightExponentValue);
        }
コード例 #2
0
        public Command(CommandBase.commVals inCommandInstruction, Object inValue)
        {
            switch (inCommandInstruction)
                {
                    case commVals.Load:
                        this.Code = (int)inCommandInstruction;
                        try
                        {
                            if (inValue.GetType() == typeof(int))
                            {
                                this.leftOperand = null;
                                this.MemoryCellNeeded = (int)inValue;
                            }
                            else
                                this.leftOperand = (PBNumber)inValue;
                        }
                        catch (Exception ex)
                        {
                            throw new IncorrectOperandType("Command(" + inCommandInstruction + ", " + inValue + ")=[ " + ex.Message + " ]");
                        }

                        break;
                    case commVals.Mem:
                        this.Code = (int)inCommandInstruction;
                        try
                        {
                            this.MemoryCellUsed = (int)inValue;
                        }
                        catch (Exception ex)
                        {
                            throw new IncorrectMemoryCellAddress("Command(" + inCommandInstruction + ", " + (String)inValue + ")=[ " + ex.Message + " ]");
                        }

                        break;
                    default :
                        this.Code = (int)inCommandInstruction;
                        try
                        {
                            if (inValue.GetType() == typeof(int))
                            {
                                this.leftOperand = null;
                                this.MemoryCellNeeded = (int)inValue;
                            }
                            else
                                this.leftOperand = (PBNumber)inValue;
                        }
                        catch (Exception ex)
                        {
                            throw new IncorrectOperandType("Command(" + inCommandInstruction + ", " + inValue + ")=[ " + ex.Message + " ]");
                        }
                        break;
                }
        }
コード例 #3
0
        /// <summary>
        /// PBNumber multiplication
        /// </summary>
        /// <param name="leftOperand"></param>
        /// <param name="rightOperand"></param>
        /// <returns></returns>
        public static PBNumber pMUL(PBNumber leftOperand, PBNumber rightOperand)
        {
            PBNumber result = new PBNumber("0", IPBNumber.NumberCapacity.PB128, IPBNumber.RoundingType.POST_BINARY);
            PBNumber[] alignedExponent = exponentsAlign((PBNumber)leftOperand.Clone(), (PBNumber)rightOperand.Clone());
            PBNumber opA = alignedExponent[0];
            PBNumber opB = alignedExponent[1];

            result.Exponent = tADD(leftOperand.Exponent, rightOperand.Exponent, false);
            result.Mantissa = pMUL_mantissa(leftOperand.Mantissa, rightOperand.Mantissa);
            result.Sign = tXOR(leftOperand.Sign, rightOperand.Sign);

            return result;
        }
コード例 #4
0
        public void calcResForInf(PBNumber inNumber, int precision)
        {
            String Sign;
            try
            {
                /* Sign */
                /*
                if ((z == 0) || (NumberFormat == 0))
                    Sign = SignCharacterLeft;
                else
                    Sign = SignCharacterRight;
                inNumber.CorrectResult = DenormalizedNumber;
                inNumber.CorrectResultExp = NormalizedNumber;

                inNumber.CorrectResult2cc = Sign + convert10to2IPart(DenormIntPart) + "," + convert10to2FPart(DenormFloatPart);
                inNumber.CorrectResult2ccExp = Sign + convertToExp(convert10to2IPart(DenormIntPart) + "," + convert10to2FPart(DenormFloatPart));

                inNumber.Error = Sign + "0,0";
                */
            }
            catch (Exception ex)
            {
                throw new FCCoreFunctionException("Func 'calcResForInf' = [ " + ex.Message + " ]");
            }
        }
コード例 #5
0
        private static PBNumber[] exponentsAlign(PBNumber opA, PBNumber opB)
        {
            switch (tCMP(opA.Exponent, opB.Exponent)) // Exponent align
            {
                case 1:
                    opB = ExponentAlign(opA, opB);
                    break;
                case -1:
                    opA = ExponentAlign(opB, opA);
                    break;
                case 0:
                default:
                    break;
            }

            PBNumber[] result = { opA, opB };
            return result;
        }
コード例 #6
0
        public void calcResForDenorm(PBNumber inNumber, int precision)
        {
            String[] tempArray;
            String Sign;
            String E, M;
            String CorrectResult, CorrectResult2cc;
            int Offset = (int)inNumber.Offset;
            try
            {
                E = inNumber.Exponent;
                M = inNumber.Mantissa;
                tempArray = new String[Math.Abs(Offset) + 1];
                for (int i = 1; i <= Offset; i++)
                    tempArray[i] = "0";
                M = String.Join("", tempArray) + M;

                /* Sign */
                Sign = inNumber.Sign;
                /*if ((z == 0) || (NumberFormat == 0))
                    Sign = SignCharacterLeft;
                else
                    Sign = SignCharacterRight;
                */
                IPBNumber.NumberFormat NumberFormat = IPBNumber.NumberFormat.INTEGER;
                switch (NumberFormat)
                {
                    case IPBNumber.NumberFormat.INTEGER:
                        CorrectResult = Sign + "0," + convert2to10FPart(M, precision);
                        CorrectResult2cc = Sign + "0," + M;
                        break;
                    /*
                     * case 1:
                        if (z == 0)
                        {
                            inNumber.CorrectResultFractionL = Sign + "0," + convert2to10FPart(M, precision);
                            inNumber.CorrectResultFraction2ccL = Sign + "0," + M;
                        }
                        else
                        {
                            inNumber.CorrectResultFractionR = Sign + "0," + convert2to10FPart(M, precision);
                            inNumber.CorrectResultFraction2ccR = Sign + "0," + M;
                        }
                        break;
                    case 2:
                        if (z == 0)
                        {
                            inNumber.CorrectResultIntervalL = Sign + "0," + convert2to10FPart(M, precision);
                            inNumber.CorrectResultInterval2ccL = Sign + "0," + M;
                        }
                        else
                        {
                            inNumber.CorrectResultIntervalR = Sign + "0," + convert2to10FPart(M, precision);
                            inNumber.CorrectResultInterval2ccR = Sign + "0," + M;
                        }
                        break;
                     */
                }
            }
            catch (Exception ex)
            {
                throw new FCCoreFunctionException("Func 'calcResForDenorm' = [ " + ex.Message + " ]");
            }
        }
コード例 #7
0
        private void pBNumberToolStripMenuItem_Click(object sender, EventArgs e)
        {
            rTBLog.Text += "\n\r _________PBNumer TESTING BEGIN";
                String testNumber = "-10000000,1379999e-1055";
                PBNumber pbNumber1 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.POST_BINARY);
                PBNumber pbNumber2 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.ZERO);
                PBNumber pbNumber3 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.NEGATIVE_INFINITY);
                PBNumber pbNumber4 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.POSITIVE_INFINITY);
                PBNumber pbNumber5 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.NEAR_INTEGER);

                String test1 = pbNumber1.toDigit(30, true);
                rTBLog.Text += "PB " + test1 + "\r\n";

                test1 = pbNumber2.toDigit(30, true);
                rTBLog.Text += "ZERO " + test1 + "\r\n";

                test1 = pbNumber3.toDigit(30, true);
                rTBLog.Text += "NInf " + test1 + "\r\n";

                test1 = pbNumber4.toDigit(30, true);
                rTBLog.Text += "PInf " + test1 + "\r\n";

                test1 = pbNumber5.toDigit(30, true);
                rTBLog.Text += "NInt " + test1 + "\r\n";
                rTBLog.Text += "\n\r _________PBNumer TESTING END";
        }
コード例 #8
0
 /// <summary>
 /// Postbinary numeric substraction
 /// </summary>
 /// <param name="leftOperand"></param>
 /// <param name="rightOperand"></param>
 /// <returns></returns>
 public PBNumber pSUB(PBNumber leftOperand, PBNumber rightOperand)
 {
     return null;
 }
コード例 #9
0
 public Command(String inOperation, int inLeftOperandFromMemory, String inRightOperand)
 {
     this.Code = getOperationCode(inOperation);
         this.rightOperand = new PBNumber(inRightOperand, IPBNumber.NumberCapacity.PB128, IPBNumber.RoundingType.POST_BINARY);
         this.MemoryCellNeeded = inLeftOperandFromMemory;
 }
コード例 #10
0
 public MemoryCell()
 {
     MemoryCellValue = null;
     CanBeErased = false;
     valueSet = false;
 }
コード例 #11
0
        public void calcResForNan(PBNumber inNumber)
        {
            try
            {
                /*
                if (NumberFormat == 0)
                {
                    inNumber.CorrectResult = "Невозможно представить в данном формате";
                    inNumber.CorrectResultExp = "Невозможно представить в данном формате";
                    inNumber.CorrectResult2cc = "Невозможно представить в данном формате";
                    inNumber.CorrectResult2ccExp = "Невозможно представить в данном формате";
                    inNumber.Error = "Невозможно представить в данном формате";
                }

                if (cycle == 2 && NumberFormat == 1)
                {
                    if (z == 0)
                    {
                        inNumber.CorrectResultFractionL = "Невозможно представить в данном формате";
                        inNumber.CorrectResultFractionExpL = "Невозможно представить в данном формате";
                        inNumber.CorrectResultFraction2ccL = "Невозможно представить в данном формате";
                        inNumber.CorrectResultFraction2ccExpL = "Невозможно представить в данном формате";
                        inNumber.ErrorFractionLeft = "Невозможно представить в данном формате";
                    }
                    if (z == 1)
                    {
                        inNumber.CorrectResultFractionR = "Невозможно представить в данном формате";
                        inNumber.CorrectResultFractionExpR = "Невозможно представить в данном формате";
                        inNumber.CorrectResultFraction2ccR = "Невозможно представить в данном формате";
                        inNumber.CorrectResultFraction2ccExpR = "Невозможно представить в данном формате";
                        inNumber.ErrorFractionRight = "Невозможно представить в данном формате";
                    }
                }

                if (cycle == 2 && NumberFormat == 2)
                {
                    if (z == 0)
                    {
                        inNumber.CorrectResultIntervalL = "Невозможно представить в данном формате";
                        inNumber.CorrectResultIntervalExpL = "Невозможно представить в данном формате";
                        inNumber.CorrectResultInterval2ccL = "Невозможно представить в данном формате";
                        inNumber.CorrectResultInterval2ccExpL = "Невозможно представить в данном формате";
                        inNumber.ErrorIntervalLeft = "Невозможно представить в данном формате";
                    }
                    if (z == 1)
                    {
                        inNumber.CorrectResultIntervalR = "Невозможно представить в данном формате";
                        inNumber.CorrectResultIntervalExpR = "Невозможно представить в данном формате";
                        inNumber.CorrectResultInterval2ccR = "Невозможно представить в данном формате";
                        inNumber.CorrectResultInterval2ccExpR = "Невозможно представить в данном формате";
                        inNumber.ErrorIntervalRight = "Невозможно представить в данном формате";
                    }
                }*/
            }
            catch (Exception ex)
            {
                throw new FCCoreFunctionException("Func 'calcResForNan' = [ " + ex.Message + " ]");
            }
        }
コード例 #12
0
        public void calcResForZero(PBNumber inNumber)
        {
            try
            {
                /*
                String Sign;
                switch (inNumber.Name)
                {
                    case "Num32":
                        Num32.Exponenta = "00000000";
                        Num32.Mantisa = "000000000000000000000"; // 21
                        break;
                    case "Num64":
                        if (z == 0)
                        {
                            Num64.Exponenta = Format == 0 ? "00000000000" : "00000000";
                            Num64.Mantisa = Format == 0 ? "000000000000000000000000000000000000000000000000" : "000000000000000000000"; // 48 - 21
                        }
                        else
                        {
                            Num64.ExponentaRight = Format == 0 ? "00000000000" : "00000000";
                            Num64.MantisaRight = Format == 0 ? "000000000000000000000000000000000000000000000000" : "000000000000000000000"; // 48 - 21
                        }
                        break;
                    case "Num128":
                        if (z == 0)
                        {
                            Num128.Exponenta = Format == 0 ? "000000000000000" : "00000000000";
                            Num128.Mantisa = Format == 0 ? "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" : "000000000000000000000000000000000000000000000000";  // 104 - 48
                        }
                        else
                        {
                            Num128.ExponentaRight = Format == 0 ? "000000000000000" : "00000000000";
                            Num128.MantisaRight = Format == 0 ? "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" : "000000000000000000000000000000000000000000000000";  // 104 - 48
                        }
                        break;
                    case "Num256":
                        if (z == 0)
                        {
                            Num256.Exponenta = Format == 0 ? "00000000000000000000" : "000000000000000";
                            Num256.Mantisa = Format == 0 ? "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; // 219 - 104
                        }
                        else
                        {
                            Num256.ExponentaRight = Format == 0 ? "00000000000000000000" : "000000000000000";
                            Num256.MantisaRight = Format == 0 ? "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; // 219 - 104
                        }
                        break;
                }

                /* Sign */
                /* if ((z == 0) || (NumberFormat == 0))
                     Sign = SignCharacterLeft;
                 else
                     Sign = SignCharacterRight;

                 if (NumberFormat == 0)
                 {
                     inNumber.CorrectResult = Sign + "0,0";
                     inNumber.CorrectResultExp = Sign + "0,0";
                     inNumber.CorrectResult2cc = Sign + "0,0";
                     inNumber.CorrectResult2ccExp = Sign + "0,0";
                     inNumber.Error = Sign + "0,0";
                 }

                 if (cycle == 2 && NumberFormat == 1)
                 {
                     if (z == 0)
                     {
                         inNumber.CorrectResultFractionL = Sign + "0,0";
                         inNumber.CorrectResultFractionExpL = Sign + "0,0";
                         inNumber.CorrectResultFraction2ccL = Sign + "0,0";
                         inNumber.CorrectResultFraction2ccExpL = Sign + "0,0";
                         inNumber.ErrorFractionLeft = Sign + "0,0";
                     }
                     if (z == 1)
                     {
                         inNumber.CorrectResultFractionR = Sign + "0,0";
                         inNumber.CorrectResultFractionExpR = Sign + "0,0";
                         inNumber.CorrectResultFraction2ccR = Sign + "0,0";
                         inNumber.CorrectResultFraction2ccExpR = Sign + "0,0";
                         inNumber.ErrorIntervalRight = Sign + "0,0";
                     }
                 }

                 if (cycle == 2 && NumberFormat == 2)
                 {
                     if (z == 0)
                     {
                         inNumber.CorrectResultIntervalL = Sign + "0,0";
                         inNumber.CorrectResultIntervalExpL = Sign + "0,0";
                         inNumber.CorrectResultInterval2ccL = Sign + "0,0";
                         inNumber.CorrectResultInterval2ccExpL = Sign + "0,0";
                         inNumber.ErrorIntervalLeft = Sign + "0,0";
                     }
                     if (z == 1)
                     {
                         inNumber.CorrectResultIntervalR = Sign + "0,0";
                         inNumber.CorrectResultIntervalExpR = Sign + "0,0";
                         inNumber.CorrectResultInterval2ccR = Sign + "0,0";
                         inNumber.CorrectResultInterval2ccExpR = Sign + "0,0";
                         inNumber.ErrorIntervalRight = Sign + "0,0";
                     }
                 }*/
            }
            catch (Exception ex)
            {
                throw new FCCoreFunctionException("Func 'calcResForZero' = [ " + ex.Message + " ]");
            }
        }
コード例 #13
0
 private void srzToolStripMenuItem_Click(object sender, EventArgs e)
 {
     PBNumber A = new PBNumber("1", IPBNumber.NumberCapacity.PB64, IPBNumber.RoundingType.POST_BINARY);
       PBNumber B = new PBNumber("1", IPBNumber.NumberCapacity.PB64, IPBNumber.RoundingType.POST_BINARY);
       PBNumber C = new PBNumber("0", IPBNumber.NumberCapacity.PB64, IPBNumber.RoundingType.POST_BINARY);
       C = PBMath.pMUL(A, B);
       Console.WriteLine("A+B=C="+C.toDigit());
 }
コード例 #14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="leftOperand"></param>
 /// <param name="rightOperand"></param>
 /// <returns></returns>
 private PBNumber SUB(PBNumber leftOperand, PBNumber rightOperand)
 {
     return ADD(leftOperand, rightOperand);
 }
コード例 #15
0
        /// <summary>
        /// Postbinary numeric addition
        /// </summary>
        /// <param name="leftOperand">Left operand of operation.</param>
        /// <param name="rightOperand">Right operand of operation.</param>
        /// <returns>Result of operation</returns>
        private PBNumber ADD(PBNumber leftOperand, PBNumber rightOperand)
        {
            PBNumber opA = (PBNumber)leftOperand.Clone();
            PBNumber opB = (PBNumber)rightOperand.Clone();
            PBNumber opC = new PBNumber("0", IPBNumber.NumberCapacity.PB128, IPBNumber.RoundingType.POST_BINARY);

            String iuA = "";
            String iuB = "";

            switch (tCMP(opA.Exponent, opB.Exponent)) // Exponent align
                {
                    case 1:
                        opB = ExponentAlign(opA, opB);
                        // log here A, B
                        iuA = "1";
                        iuB = "";
                        break;
                    case -1:
                        opA = ExponentAlign(opB, opA);
                        // log here A, B
                        iuA = "";
                        iuB = "1";
                        break;
                    case 0:
                    default:
                        // log here A, B
                        break;
                }

            PBConvertion pbconvertion = new PBConvertion();
            int a = Int32.Parse(pbconvertion.convert2to10IPart(opA.Exponent));

            String str = tADD(iuA + opA.Mantissa, iuB + opB.Mantissa, false);
            int iuPosition = str.IndexOf('1');
            a -= iuPosition;
            str = str.Substring(iuPosition);

            opC.Mantissa = str.Substring(1);

            opC.Exponent = pbconvertion.convert10to2IPart(a.ToString());
            // log here C
            return opC;
        }
コード例 #16
0
 /// <summary>
 /// Shifts PBNumber number with regard to shiftValue sign(shift direction) and modulus(counts of shifts).
 /// </summary>
 /// <param name="operand">PBNumber to shift.</param>
 /// <param name="shiftValue">Sign shows direction of shift; Modulus shows counts of shifts.</param>
 /// <returns>Shifted PBNumber</returns>
 public static PBNumber Shift(PBNumber operand, int shiftValue)
 {
     PBConvertion pbconvertion = new PBConvertion();
     int expA = Int32.Parse(pbconvertion.convert2to10IPart(operand.Exponent));
     expA += shiftValue;
     IPBNumber.IFPartsOfNumber ipbn = new IPBNumber.IFPartsOfNumber();
     if (shiftValue != 0)
     {
         if (shiftValue > 0)
         {
             String newMantissa = AddSymbols("0", "1" + operand.Mantissa, shiftValue - 1, true);
             operand.Mantissa = newMantissa;
         }
         else
         {
             String precipitated = operand.Mantissa.Substring(operand.Mantissa.Length + shiftValue);
             operand.Mantissa = AddSymbols("0", operand.Mantissa, Math.Abs(shiftValue), true);
             if (precipitated.Length >= 1)
             {
                 operand.Round(IPBNumber.RoundingType.POST_BINARY, operand.Mantissa, 104, ipbn, 0, IPBNumber.NumberCapacity.PB128);
             }
         }
     }
     operand.Exponent = pbconvertion.convert10to2IPart(expA.ToString());
     return operand;
 }
コード例 #17
0
        private void tetraMathToolStripMenuItem_Click(object sender, EventArgs e)
        {
            rTBLog.Text += "\n\r _________TETRA MATH TESTING BEGIN";
                String testNumber = "-10000000,1379999e-1055";
                PBNumber pbNumber1 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.POST_BINARY);
                PBNumber pbNumber2 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.ZERO);
                PBNumber pbNumber3 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.NEGATIVE_INFINITY);
                PBNumber pbNumber4 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.POSITIVE_INFINITY);
                PBNumber pbNumber5 = new PBNumber(testNumber, IPBNumber.NumberCapacity.PB256, IPBNumber.RoundingType.NEAR_INTEGER);

                PBConvertion pbc = new PBConvertion();
                PBMath pbmath = new PBMath();
                pbNumber3 = pbmath.pADD(pbNumber1, pbNumber2);

                String test1 = pbmath.pCMP(pbNumber1, pbNumber1).ToString();
                String test2 = pbmath.pCMP(pbNumber1, pbNumber2).ToString();
                String test3 = pbmath.pCMP(pbNumber2, pbNumber1).ToString();

                rTBLog.Text += "\r\n" + test1;
                rTBLog.Text += "\r\n" + test2;
                rTBLog.Text += "\r\n" + test3;
                rTBLog.Text += "\n\r _________TETRA MATH TESTING END";
        }
コード例 #18
0
        /// <summary>
        /// Function converts postbinary normilized number to number in 10cc
        /// </summary>
        /// <param name="inNumber">PostBinary number.</param>
        /// <param name="precision"></param>
        public String calcResForNorm(PBNumber inNumber, int precision)
        {
            String binIPartOut, binFPartOut, Sign;
            String[] tempArray;
            String M, E;
            String CorrectResult = "", CorrectResult2cc;
            try
            {
                E = inNumber.Exponent;
                M = inNumber.Mantissa;

                M = "1" + M;
                E = convert2to10IPart(E);
                int iE = int.Parse(E) - (int)inNumber.Offset;
                if (iE > M.Length)
                {
                    tempArray = new String[Math.Abs(iE) + 1];
                    for (int i = 0; i <= iE; i++)
                        tempArray[i] = "0";
                    M = M + String.Join("", tempArray);

                }
                if (iE >= 0)
                {
                    if (iE + 1 <= M.Length)
                    {
                        binIPartOut = M.Substring(0, iE + 1);
                        //binFPartOut = "0" + M.Substring(iE + 1);
                        binFPartOut = M.Substring(iE + 1);
                    }
                    else
                    {
                        int temp = M.Length;
                        binIPartOut = M.Substring(0, temp);
                        binFPartOut = M.Substring(temp);
                    }
                }
                else
                {
                    // After Research
                    int max = 0;
                    tempArray = new String[Math.Abs(iE) + 1];
                    for (int i = 1; i < Math.Abs(iE); i++) //for (int i = -1; i > iE; i--)
                    {
                        tempArray[max] = "0";
                        max++;
                    }
                    if (max > 0)
                        M = String.Join("", tempArray) + M;
                    //else
                    //    M = "0" + M;

                    binIPartOut = "0";
                    binFPartOut = M;
                }

                /* Sign */
                Sign = inNumber.Sign;

                if (binFPartOut.IndexOf('M') == -1)
                {
                    return deleteNonSignificantBits((Sign == "1" ? "-" : "") + convert2to10IPart(binIPartOut) + "," + convert2to10FPart(binFPartOut, precision));
                    //CorrectResult2cc = Sign + binIPartOut + "," + binFPartOut;
                }else
                {
                    // split binary float part to 2 parts //  ex. 0101m1 -> [010101:010111]
                    String lowBound = binFPartOut.Replace('M', '0').Replace('A', '1');
                    String highBound = binFPartOut.Replace('M', '1').Replace('A', '0');
                    String iPart = convert2to10IPart(binIPartOut);
                    CorrectResult = deleteNonSignificantBits((Sign == "1" ? "-" : "") + iPart + "," + convert2to10FPart(lowBound, precision));
                    CorrectResult += ':' + deleteNonSignificantBits((Sign == "1" ? "-" : "") + iPart + "," + convert2to10FPart(highBound, precision));
                    return CorrectResult;
                }
            }
            catch (Exception ex)
            {
                throw new FCCoreFunctionException("Func 'calcResForNorm' = [ " + ex.Message + " ]");
            }

            //CorrectResult = deleteNonSignificantBits(CorrectResult);
            //return CorrectResult;
        }
コード例 #19
0
 /// <summary>
 /// Postbinary numeric negative
 /// </summary>
 /// <param name="operand"></param>
 /// <returns></returns>
 public PBNumber NEG(PBNumber operand)
 {
     operand.Sign = operand.Sign == "0" ? "1" : "0";
     return operand;
 }
コード例 #20
0
 public Command(String inOperation, String inLeftOperand, String inRightOperand)
 {
     switch (inOperation)
         {
             case "+": this.Code = 1; break;
             case "-": this.Code = 2; break;
             case "*": this.Code = 3; break;
             case "/": this.Code = 4; break;
             // Exponent need to be checked in Parser.cs
             case "^": this.Code = 5; break;
             default: break;
         }
         this.leftOperand = new PBNumber(inLeftOperand, IPBNumber.NumberCapacity.PB128, IPBNumber.RoundingType.POST_BINARY);
         this.rightOperand = new PBNumber(inRightOperand, IPBNumber.NumberCapacity.PB128, IPBNumber.RoundingType.POST_BINARY);
 }
コード例 #21
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="leftOperand"></param>
        /// <param name="rightOperand"></param>
        /// <returns></returns>
        public PBNumber pADD(PBNumber leftOperand, PBNumber rightOperand)
        {
            //if (pCMP(leftOperand, rightOperand))
            if (leftOperand.Sign != rightOperand.Sign)
            {

            }
            else
            {
                return ADD(leftOperand, rightOperand);
            }

            return ADD(leftOperand, rightOperand);
        }
コード例 #22
0
        public Command(String inOperation, int inLeftOperandFromMemory, int inRightOperandFromMemory)
        {
            this.Code = getOperationCode(inOperation);

                this.leftOperand = null;
                this.rightOperand = null;

                this.MemoryCellNeededExtra = inRightOperandFromMemory;
                this.MemoryCellNeeded = inLeftOperandFromMemory;
        }
コード例 #23
0
 /// <summary>
 /// </summary>
 /// <param name="leftOperand"></param>
 /// <param name="rightOperand"></param>
 /// <returns></returns>
 //TODO: add exponent align
 public PBNumber pAND(PBNumber leftOperand, PBNumber rightOperand)
 {
     PBNumber opA = (PBNumber)leftOperand.Clone();
     PBNumber opB = (PBNumber)rightOperand.Clone();
     String result = "";
     for (int i = 0; i < 10; i++)//change 10 to Mantissa lenght
     {
         switch (opA.Mantissa[i])
         {
             case '0':
                 {
                     result += '0';
                     break;
                 }
             case '1':
                 {
                     result += '1';
                     break;
                 }
             case 'A':
                 {
                     switch (opB.Mantissa[i])
                     {
                         case '0':
                             {
                                 result += '0';
                                 break;
                             }
                         case '1':
                             {
                                 result += 'A';
                                 break;
                             }
                         case 'A':
                             {
                                 result += 'A';
                                 break;
                             }
                         case 'M':
                             {
                                 result += 'M';
                                 break;
                             }
                     }
                     break;
                 }
             case 'M':
                 {
                     switch (opB.Mantissa[i])
                     {
                         case '0':
                             {
                                 result += '0';
                                 break;
                             }
                         case '1':
                             {
                                 result += 'M';
                                 break;
                             }
                         case 'A':
                             {
                                 result += 'M';
                                 break;
                             }
                         case 'M':
                             {
                                 result += 'M';
                                 break;
                             }
                     }
                     break;
                 }
         }
     }
     return null;
 }
コード例 #24
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="leftOperand"></param>
 /// <param name="rightOperand"></param>
 /// <returns></returns>
 public int pCMP(PBNumber leftOperand, PBNumber rightOperand)
 {
     if (leftOperand.Sign != rightOperand.Sign)
     {
         return (leftOperand.Sign == "0") ? 1 : -1;
     }
     else
     {
         int cmpExponent = tCMP(leftOperand.Exponent, rightOperand.Exponent);
         if (cmpExponent != 0)
         {
             return cmpExponent;
         }
         else
         {
             return tCMP(leftOperand.Mantissa, rightOperand.Mantissa);
         }
     }
 }
コード例 #25
0
        public static void CreatePBNumber()
        {
            String testNumber = "123.123";

            PBNumber pbNUmber = new PBNumber(testNumber, NumberCapacity.PB128, RoundingType.NEAR_INTEGER);
        }