ALU { public String floatDivision (String operand1, String operand2, int eLength, int sLength) { if (operand2.equals(ALU.repeatedString("0", 1+eLength+sLength))){ return "00"+ALU.repeatedString("1", eLength)+ALU.repeatedString("0", sLength); } char sign = charOp(booleanXOR,operand1.charAt(0), operand2.charAt(0)); if (operand1.substring(1).indexOf("1")==-1){ return "0"+sign+repeatedString("0", eLength+sLength); } if (operand2.substring(1).indexOf("1")==-1){ return "1"+sign+repeatedString("1", eLength)+repeatedString("0", sLength); } int order1 = Integer.parseInt(integerTrueValue('0'+operand1.substring(1,eLength+1))); int order2 = Integer.parseInt(integerTrueValue('0'+operand2.substring(1,eLength+1))); long shift = (long) (Math.pow(2, eLength-1)-1); long orderResult = order1-order2+shift; String manttisa1 = "1."+operand1.substring(eLength+1); String manttisa2 = "1."+operand2.substring(eLength+1); if (order1==0){ manttisa1 = "0."+operand1.substring(eLength+1); } if (order2==0){ manttisa2 = "0."+operand1.substring(eLength+1); } String manttisaResult = trueFormDivision(manttisa1, manttisa2, sLength+1); manttisaResult = manttisaResult.charAt(0)+"."+manttisaResult.substring(1); while (manttisaResult.charAt(manttisaResult.indexOf('.')-1)!='1'){ manttisaResult = movePoint(manttisaResult, 1); orderResult--; if (orderResult==0){ return "0"+sign+repeatedString("0", eLength)+manttisaResult.split("\\.")[1]; } } if (orderResult > Math.pow(2, eLength)-1){ return "1"+sign+repeatedString("1", eLength)+repeatedString("0", sLength); } StringBuilder result = new StringBuilder(); result.append('0'); result.append(sign); result.append(integerRepresentation(String.valueOf(orderResult), eLength)); result.append(manttisaResult.split("\\.")[1].substring(0,sLength)); return result.toString(); }  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 testFloatDivision() { ALU alu = new ALU(); assertEquals("000111111011000000", alu.floatDivision("00111110111000000", "00111111000000000", 8, 8)); }