ALU { public String floatTrueValue (String operand, int eLength, int sLength) { boolean isNegative = operand.charAt(0)=='1'; boolean notStandardized = operand.matches(String.format("(1|0)(0{%d})[01]{%d}",eLength,sLength)); if (floatIsInfinity(operand, eLength, sLength)){ return (isNegative?"-":"+")+"Inf"; } if (operand.matches(String.format("(1|0)(1{%d})[01]{%d}",eLength,sLength))){ return "NaN"; } int shift = (int)(Math.pow(2, eLength-1)-1); int exponentValue = -shift; double mantissaValue = 1; if (notStandardized){ exponentValue = -shift+1; mantissaValue = 0; } String mantissa = operand.substring(eLength+1); for(int i=eLength;i>=1;i--){ exponentValue+= Integer.parseInt(operand.substring(i,i+1)) * Math.pow(2, eLength-i); } for(int i=0;i<sLength;i++){ mantissaValue+= Double.parseDouble(mantissa.substring(i,i+1)) * Math.pow(2, -i-1); } double result = mantissaValue * Math.pow(2, exponentValue); if (result == (int)result){ return (isNegative?"-":"") + String.valueOf((int)result)+".0"; } String resultRepresentation = String.valueOf(result); if (resultRepresentation.contains("E")){ String[] split = resultRepresentation.split("E"); resultRepresentation = movePoint(split[0], Integer.parseInt(split[1])); } return (isNegative?"-":"") + resultRepresentation; }  static void main(String[] args); static final boolean floatIsInfinity(String input, int eLength, int sLength); static final String complementLength(String binary, int length); static final String repeatedString(String str, int times); static final String bitOp(String oneBitOperand1, String oneBitOperand2, BinaryOperator<Boolean> op); static final boolean isSignTheSame(String binary1, String binary2); static String movePoint(String operand, int offset); static final char charOp(BinaryOperator<Boolean> op, Character... bits); static final String stringOp(String operand1, String operand2, BinaryOperator<Boolean> op); static final boolean xor(boolean operand1, boolean operand2); static int minBinaryLong(int number); static String integerBinRepresentationInMinLength(String decimalNumber); static String get2sComplement(String binaryNumber, boolean isNegative); String integerRepresentation(String number, int length); String floatRepresentation(String number, int eLength, int sLength); String ieee754(String number, int length); String integerTrueValue(String operand); String floatTrueValue(String operand, int eLength, int sLength); String negation(String operand); String leftShift(String operand, int n); String logRightShift(String operand, int n); String ariRightShift(String operand, int n); String fullAdder(char x, char y, char c); String claAdder(String operand1, String operand2, char c); String oneAdder(String operand); String adder(String operand1, String operand2, char c, int length); String integerAddition(String operand1, String operand2, int length); String integerSubtraction(String operand1, String operand2, int length); String integerMultiplication(String operand1, String operand2, int length); String integerDivision(String operand1, String operand2, int length); String signedAddition(String operand1, String operand2, int length); String floatAddition(String operand1, String operand2, int eLength, int sLength, int gLength); String floatSubtraction(String operand1, String operand2, int eLength, int sLength, int gLength); String floatMultiplication(String operand1, String operand2, int eLength, int sLength); String floatDivision(String operand1, String operand2, int eLength, int sLength); String trueFormDivision(String operand1, String operand2, int length); static final BinaryOperator<Boolean> booleanAnd; static final BinaryOperator<Boolean> booleanOr; static final BinaryOperator<Boolean> booleanXOR; }
@Test public void testFloatTrueValue() { ALU alu = new ALU(); assertEquals("11.375", alu.floatTrueValue("01000001001101100000", 8, 11)); }
@Test public void testFloatTrueValue1(){ assertEquals("+Inf",ALU.floatTrueValue("011110000000000", 4, 10)); }
@Test public void testFloatTrueValue2(){ assertEquals("0.0009765625",ALU.floatTrueValue("000000001", 4, 4)); }