/// <summary> /// Denormolizes number /// </summary> /// <param name="dataString">Input String to dernomolize</param> /// <param name="NumberFormat">Indicates format of input number</param> /// <returns>Denormolized number as String</returns> public IPBNumber.IFPartsOfNumber DenormalizeNumber(String dataString, IPBNumber.NumberFormat inNumberFormat) { String denormNumber = ""; String denormIntPart = "", denormFloatPart = ""; String ExpSign, Sign = "0", SignCharacter = "+"; String E; String[] tempArray; IPBNumber.IFPartsOfNumber returnValue = new IPBNumber.IFPartsOfNumber(); try { ExpSign = dataString.Substring(dataString.IndexOf('e') + 1, 1); if (dataString[0] == '+') { if (inNumberFormat == 0) { Sign = "0"; SignCharacter = "+"; } else { /* if (Left_Right == PartOfNumber.Left) { SignLeft = "0"; SignCharacterLeft = "+"; } else { SignRight = "0"; SignCharacterRight = "+"; }*/ } } else if (dataString[0] == '-') { if (inNumberFormat == 0) { Sign = "1"; SignCharacter = "-"; } else { /* if (Left_Right == PartOfNumber.Left) { SignLeft = "1"; SignCharacterLeft = "-"; } else { SignRight = "1"; SignCharacterRight = "-"; }*/ } } else { if (inNumberFormat == 0) { Sign = "0"; SignCharacter = "+"; } else { /* if (Left_Right == PartOfNumber.Left) { SignLeft = "0"; SignCharacterLeft = "+"; } else { SignRight = "0"; SignCharacterRight = "+"; }*/ } } returnValue.Sign = Sign; //throw new Exception("Func [selectSEM]:= NoSignException."); int index = dataString.IndexOf('e') + 1; if (index < dataString.Length) E = dataString.Substring(index, dataString.Length - index); else throw new Exception("Func [selectSEM]:= NoExponentaException."); int iExp = Math.Abs(int.Parse(E)); if ((dataString[0] == '-') || (dataString[0] == '+')) dataString = dataString.Substring(1); /*iPart */ denormIntPart = dataString.Substring(0, dataString.IndexOf(',')); index = dataString.IndexOf(',') + 1; /*fPart*/ denormFloatPart = dataString.Substring(index, dataString.IndexOf('e') - index);////+1 if (ExpSign == "+") { String fPartTemp = denormFloatPart; if (iExp > 0) { tempArray = new String[Math.Abs(iExp - denormFloatPart.Length)]; for (int i = 0; i < (Math.Abs(iExp - denormFloatPart.Length)); i++) tempArray[i] = "0"; fPartTemp = fPartTemp + String.Join("", tempArray); denormFloatPart = "0"; } denormIntPart = denormIntPart + fPartTemp.Substring(0, iExp); denormFloatPart = fPartTemp.Substring(iExp); if (denormFloatPart.Length == 0) denormFloatPart = "0"; } else { String iPartTemp = denormIntPart; tempArray = new String[Math.Abs(iExp - denormIntPart.Length)]; for (int i = 0; i < Math.Abs((iExp - denormIntPart.Length)); i++) tempArray[i] = "0"; iPartTemp = String.Join("", tempArray) + iPartTemp; if (iExp > denormIntPart.Length) { denormFloatPart = iPartTemp + denormFloatPart; denormIntPart = "0"; } else { denormFloatPart = iPartTemp.Substring(iPartTemp.Length - iExp) + denormFloatPart; if (iPartTemp.Length != iExp) denormIntPart = iPartTemp.Substring(0, iPartTemp.Length - iExp); else denormIntPart = "0"; } } // iPart = myUtil.deleteZeroFromNumber(iPart); // if (iPart[0] == '0') // iPart = iPart.Substring(1); while ((denormIntPart[0] == '0') && (denormIntPart.Length > 1)) { denormIntPart = denormIntPart.Substring(1); } // Compact to one statement num32 = num64 = num128 = num256 = denorm denormNumber = SignCharacter + denormIntPart + "," + denormFloatPart; //Num32.Denormalized = Num64.Denormalized = Num128.Denormalized = Num256.Denormalized = if (inNumberFormat == 0) { /*Num32.IntPartDenormalized = Num64.IntPartDenormalized = Num128.IntPartDenormalized = Num256.IntPartDenormalized = IntPartDenormalized = denormIntPart; Num32.FloatPartDenormalized = Num64.FloatPartDenormalized = Num128.FloatPartDenormalized = Num256.FloatPartDenormalized = FloatPartDenormalized = denormFloatPart;*/ //DenormIntPart = denormIntPart; returnValue.IntegerPart = denormIntPart; //DenormFloatPart = denormFloatPart; returnValue.FloatPart = denormFloatPart; } else { /* if (Left_Right == PartOfNumber.Left) { IntPartDenormalizedFILeft = denormIntPart; FloatPartDenormalizedFILeft = denormFloatPart; } else { IntPartDenormalizedFIRight = denormIntPart; FloatPartDenormalizedFIRight = denormFloatPart; } //Num32.IntPartDenormalizedFI = Num64.IntPartDenormalizedFI = Num128.IntPartDenormalizedFI = Num256.IntPartDenormalizedFI = IntPartDenormalizedFI = denormIntPart; //Num32.FloatPartDenormalizedFI = Num64.FloatPartDenormalizedFI = Num128.FloatPartDenormalizedFI = Num256.FloatPartDenormalizedFI = FloatPartDenormalizedFI = denormFloatPart; DenormIntPartFI = denormIntPart; DenormFloatPartFI = denormFloatPart; */ } return returnValue; } catch (Exception ex) { //throw new FCCoreFunctionException("Exception in Func ['selectSEM'] Mess=[" + ex.Message + "]"); throw new Exception(ex.Message, ex.InnerException); } }
/// <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; }