{
if( val1 instanceof FixedPoint )
{
if( val2.equals( FixedPoint.ZERO ) )
{
throw new VirtualMachineException( 0, "Division by zero" );
}
else
{
final Instance instance =
getVirtualMachine().newInstance( "double" );
instance.set(
"value",
((FixedPoint) val1).div( (FixedPoint) val2 )
);
return instance;
}
}
else if( val1 instanceof Long )
{
if( ((Long) val2).longValue() == 0 )
{
throw new VirtualMachineException( 0, "Division by zero" );
}
else
{
final Instance instance =
getVirtualMachine().newInstance( "long" );
instance.set(
"value",
new Long(
((Long) val1).longValue() /
( (Long) val2 ).longValue()
)
);
return instance;
}
}
else if( val1 instanceof Integer )
{
if( ((Integer) val2).intValue() == 0 )
{
throw new VirtualMachineException( 0, "Division by zero" );
}
else
{
final Instance instance =
getVirtualMachine().newInstance( "int" );
instance.set(
"value",
new Integer(
((Integer) val1).intValue() /
( (Integer) val2 ).intValue()
)
);
return instance;
}
}
else if( val1 instanceof Short )
{
if( ((Short) val2).shortValue() == 0 )
{
throw new VirtualMachineException( 0, "Division by zero" );
}
else
{
final Instance instance =
getVirtualMachine().newInstance( "short" );
instance.set(
"value",
new Short( (short)
(((Short) val1).shortValue() /
( (Short) val2 ).shortValue() )
)
);
return instance;
}
}
else
{
if( ((Byte) val2).byteValue() == 0 )
{
throw new VirtualMachineException( 0, "Division by zero" );
}
else
{
final Instance instance =
getVirtualMachine().newInstance( "byte" );