BasicFunctions { public static short div(short var1,short var2) { if(var1<=0) throw new ArithmeticException("Variable 1 should be positive"); if(var2<var1) throw new ArithmeticException("Variable 2 should be greater or equal to variable 1"); int value1=var1; int value2=var2; short result=0; for(int i=0;i<15;i++) { result<<=1; value1<<=1; if(value1>=value2) { value1=L_sub(value1,value2); result=add(result,(short)1); } } return result; } BasicFunctions(); static short checkOverflow(int value); static int checkIntOverflow(long value); static short add(short var1,short var2); static short sub(short var1,short var2); static short mult(short var1,short var2); static short mult_r(short var1,short var2); static short abs(short var1); static short div(short var1,short var2); static int L_mult(short var1,short var2); static int L_add(int var1,int var2); static int L_sub(int var1,int var2); static short norm(int var1); static final short A; static final short B; static final short MIC; static final short MAC; static final short INVA; static final short DLB; static final short QLB; static final short H; static final short NRFAC; static final short FAC; }
@Test public void testDiv() { assertEquals(Short.MAX_VALUE, BasicFunctions.div((short)100,(short)100)); assertEquals(8192, BasicFunctions.div((short)100,(short)400)); }