/// <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; }
/// <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; }
/// <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; }