mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-18 00:19:32 -08:00
Add ceiling to NumberInterface and the two numbers that implement it.
This commit is contained in:
parent
9a6b695f97
commit
afb57cf69b
|
@ -93,6 +93,11 @@ public class NaiveNumber implements NumberInterface {
|
||||||
return this.compareTo(ZERO);
|
return this.compareTo(ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int ceiling() {
|
||||||
|
return (int) Math.ceil(value);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NumberInterface promoteTo(Class<? extends NumberInterface> toClass) {
|
public NumberInterface promoteTo(Class<? extends NumberInterface> toClass) {
|
||||||
if (toClass == this.getClass()) return this;
|
if (toClass == this.getClass()) return this;
|
||||||
|
|
|
@ -79,6 +79,12 @@ public interface NumberInterface {
|
||||||
*/
|
*/
|
||||||
int signum();
|
int signum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the least integer greater than or equal to the number.
|
||||||
|
* @return the least integer >= the number, if int can hold the value.
|
||||||
|
*/
|
||||||
|
int ceiling();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promotes this class to another number class.
|
* Promotes this class to another number class.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.nwapw.abacus.number;
|
package org.nwapw.abacus.number;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.MathContext;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
public class PreciseNumber implements NumberInterface {
|
public class PreciseNumber implements NumberInterface {
|
||||||
|
@ -49,7 +50,7 @@ public class PreciseNumber implements NumberInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NumberInterface multiply(NumberInterface multiplier) {
|
public NumberInterface multiply(NumberInterface multiplier) {
|
||||||
return new PreciseNumber(value.multiply(((PreciseNumber) multiplier).value));
|
return new PreciseNumber(this.value.multiply(((PreciseNumber) multiplier).value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -94,6 +95,11 @@ public class PreciseNumber implements NumberInterface {
|
||||||
return value.signum();
|
return value.signum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int ceiling() {
|
||||||
|
return (int) Math.ceil(value.doubleValue());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NumberInterface negate() {
|
public NumberInterface negate() {
|
||||||
return new PreciseNumber(value.negate());
|
return new PreciseNumber(value.negate());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user