Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,21 @@ public int divide(final int nFirstInteger, final int nSecondInteger) {
final double dbFirstNumber = IntToDoubleConverter.Convert(nFirstInteger);
final double dbSecondNumber = IntToDoubleConverter.Convert(nSecondInteger);
final double dbQuotient = dbFirstNumber / dbSecondNumber;
double dbRoundedQuotient = (double) Constants.INTEGER_ORIGIN_ZERO_VALUE;
if (this.firstIsSmallerThanSecondDoubleComparator.FirstIsSmallerThanSecond(dbQuotient,
(double) Constants.INTEGER_ORIGIN_ZERO_VALUE)) {
dbRoundedQuotient = Math.ceil(dbQuotient);
} else if (this.firstIsLargerThanSecondDoubleComparator.FirstIsLargerThanSecond(dbQuotient,
(double) Constants.INTEGER_ORIGIN_ZERO_VALUE)) {
dbRoundedQuotient = Math.floor(dbQuotient);
}
final double constantsIntegerOriginZeroValueAsDouble = IntToDoubleConverter.Convert(
Constants.INTEGER_ORIGIN_ZERO_VALUE
);
final boolean dbQuotientIsSmallerThanConstantIntegerOriginZeroValueAsDouble =
this.firstIsSmallerThanSecondDoubleComparator.FirstIsSmallerThanSecond(dbQuotient,
IntToDoubleConverter.Convert(Constants.INTEGER_ORIGIN_ZERO_VALUE));
final boolean dbQuotientIsLargerThanConstantIntegerOriginZeroValueAsDouble =
this.firstIsLargerThanSecondDoubleComparator.FirstIsLargerThanSecond(dbQuotient,
IntToDoubleConverter.Convert(Constant.INTEGER_ORIGIN_ZERO_VALUE));
//TODO: refactor to use ternary operator factory and classes
final double dbRoundedQuotient = dbQuotientIsSmallerThanConstantIntegerOriginZeroValueAsDouble ?
Math.ceil(constantsIntegerOriginZeroValueAsDouble) :
dbQuotientIsLargerThanConstantIntegerOriginZeroValueAsDouble ?
Math.floor(constantsIntegerOriginZeroValueAsDouble :
Constant.INTEGER_ORIGIN_ZERO_VALUE; //if neither smaller nor larger, it must be equal
final int nIntegerQuotient = DoubleToIntConverter.Convert(dbRoundedQuotient);
return nIntegerQuotient;
}
Expand Down