@Test public void shouldRoundUpNumbersGreaterThan10() { assertThat(ops.roundUp(-101l, 0), is(-101l)); assertThat(ops.roundUp(-101l, 1), is(-101l)); assertThat(ops.roundUp(-101l, 1), is(-101l)); assertThat(ops.roundUp(-101l, -1), is(-100l)); assertThat(ops.roundUp(-109l, -1), is(-110l)); assertThat(ops.roundUp(101l, 0), is(101l)); assertThat(ops.roundUp(101l, 0), is(101l)); assertThat(ops.roundUp(101l, 1), is(101l)); assertThat(ops.roundUp(101l, 1), is(101l)); assertThat(ops.roundUp(109l, -1), is(110l)); assertThat(ops.roundUp(101l, -1), is(100l)); }
@Override public Long roundUp( Long value, int decimalShift ) { if (value == 0) return 0l; if (decimalShift >= 0) return value; long shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10l; shiftedValueP5 += 5l; long shiftedValue = shiftedValueP5 / 10l; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10l; return shiftedValue; }
LongOperations implements MathOperations<Long>, Comparator<Long> { @Override public Long roundUp( Long value, int decimalShift ) { if (value == 0) return 0l; if (decimalShift >= 0) return value; long shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10l; shiftedValueP5 += 5l; long shiftedValue = shiftedValueP5 / 10l; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10l; return shiftedValue; } }
LongOperations implements MathOperations<Long>, Comparator<Long> { @Override public Long roundUp( Long value, int decimalShift ) { if (value == 0) return 0l; if (decimalShift >= 0) return value; long shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10l; shiftedValueP5 += 5l; long shiftedValue = shiftedValueP5 / 10l; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10l; return shiftedValue; }  }
LongOperations implements MathOperations<Long>, Comparator<Long> { @Override public Long roundUp( Long value, int decimalShift ) { if (value == 0) return 0l; if (decimalShift >= 0) return value; long shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10l; shiftedValueP5 += 5l; long shiftedValue = shiftedValueP5 / 10l; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10l; return shiftedValue; }  @Override Class<Long> getOperandClass(); @Override Long add( Long value1,
                     Long value2 ); @Override Long subtract( Long value1,
                          Long value2 ); @Override Long multiply( Long value1,
                          Long value2 ); @Override double divide( Long value1,
                          Long value2 ); @Override Long negate( Long value ); @Override Long increment( Long value ); @Override Long maximum( Long value1,
                         Long value2 ); @Override Long minimum( Long value1,
                         Long value2 ); @Override int compare( Long value1,
                        Long value2 ); @Override BigDecimal asBigDecimal( Long value ); @Override Long fromBigDecimal( BigDecimal value ); @Override Long createZeroValue(); @Override Long create( int value ); @Override Long create( long value ); @Override Long create( double value ); @Override double sqrt( Long value ); @Override Comparator<Long> getComparator(); @Override Long random( Long minimum,
                        Long maximum,
                        Random rng ); @Override double doubleValue( Long value ); @Override float floatValue( Long value ); @Override int intValue( Long value ); @Override long longValue( Long value ); @Override short shortValue( Long value ); @Override int getExponentInScientificNotation( Long value ); @Override Long roundUp( Long value,
                         int decimalShift ); @Override Long roundDown( Long value,
                           int decimalShift ); @Override Long keepSignificantFigures( Long value,
                                        int numSigFigs ); }
LongOperations implements MathOperations<Long>, Comparator<Long> { @Override public Long roundUp( Long value, int decimalShift ) { if (value == 0) return 0l; if (decimalShift >= 0) return value; long shiftedValueP5 = Math.abs(value); for (int i = 0; i != (-decimalShift - 1); ++i) shiftedValueP5 /= 10l; shiftedValueP5 += 5l; long shiftedValue = shiftedValueP5 / 10l; if (shiftedValue * 10l - shiftedValueP5 >= 5) ++shiftedValue; shiftedValue *= Long.signum(value); for (int i = 0; i != -decimalShift; ++i) shiftedValue *= 10l; return shiftedValue; }  @Override Class<Long> getOperandClass(); @Override Long add( Long value1,
                     Long value2 ); @Override Long subtract( Long value1,
                          Long value2 ); @Override Long multiply( Long value1,
                          Long value2 ); @Override double divide( Long value1,
                          Long value2 ); @Override Long negate( Long value ); @Override Long increment( Long value ); @Override Long maximum( Long value1,
                         Long value2 ); @Override Long minimum( Long value1,
                         Long value2 ); @Override int compare( Long value1,
                        Long value2 ); @Override BigDecimal asBigDecimal( Long value ); @Override Long fromBigDecimal( BigDecimal value ); @Override Long createZeroValue(); @Override Long create( int value ); @Override Long create( long value ); @Override Long create( double value ); @Override double sqrt( Long value ); @Override Comparator<Long> getComparator(); @Override Long random( Long minimum,
                        Long maximum,
                        Random rng ); @Override double doubleValue( Long value ); @Override float floatValue( Long value ); @Override int intValue( Long value ); @Override long longValue( Long value ); @Override short shortValue( Long value ); @Override int getExponentInScientificNotation( Long value ); @Override Long roundUp( Long value,
                         int decimalShift ); @Override Long roundDown( Long value,
                           int decimalShift ); @Override Long keepSignificantFigures( Long value,
                                        int numSigFigs );  }