1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-01-15 19:35:20 +00:00

Merge branch 'sin'

# Conflicts:
#	src/main/java/org/nwapw/abacus/Abacus.java
#	src/main/java/org/nwapw/abacus/plugin/PluginManager.java
This commit is contained in:
2017-08-04 12:04:37 -07:00
10 changed files with 461 additions and 84 deletions

View File

@@ -94,8 +94,23 @@ public class NaiveNumber implements NumberInterface {
}
@Override
public int ceiling() {
return (int) Math.ceil(value);
public NumberInterface ceiling() {
return new NaiveNumber(Math.ceil(value));
}
@Override
public NumberInterface floor() {
return new NaiveNumber(Math.floor(value));
}
@Override
public NumberInterface fractionalPart() {
return new NaiveNumber(value - Math.floor(value));
}
@Override
public int intValue() {
return (int)value;
}
@Override

View File

@@ -83,7 +83,26 @@ public interface NumberInterface {
* 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();
NumberInterface ceiling();
/**
* Return the greatest integer less than or equal to the number.
* @return the greatest int >= the number, if int can hold the value.
*/
NumberInterface floor();
/**
* Returns the fractional part of the number.
* @return the fractional part of the number.
*/
NumberInterface fractionalPart();
/**
* Returns the integer representation of this number, discarding any fractional part,
* if int can hold the value.
* @return
*/
int intValue();
/**
* Promotes this class to another number class.

View File

@@ -12,15 +12,15 @@ public class PreciseNumber implements NumberInterface {
/**
* The number one.
*/
static final PreciseNumber ONE = new PreciseNumber(BigDecimal.ONE);
public static final PreciseNumber ONE = new PreciseNumber(BigDecimal.ONE);
/**
* The number zero.
*/
static final PreciseNumber ZERO = new PreciseNumber(BigDecimal.ZERO);
public static final PreciseNumber ZERO = new PreciseNumber(BigDecimal.ZERO);
/**
* The number ten.
*/
static final PreciseNumber TEN = new PreciseNumber(BigDecimal.TEN);
public static final PreciseNumber TEN = new PreciseNumber(BigDecimal.TEN);
/**
* The value of the PreciseNumber.
@@ -99,8 +99,38 @@ public class PreciseNumber implements NumberInterface {
}
@Override
public int ceiling() {
return (int) Math.ceil(value.doubleValue());
public NumberInterface ceiling() {
String str = value.toPlainString();
int decimalIndex = str.indexOf('.');
if(decimalIndex != -1){
return this.floor().add(ONE);
}
return this;
}
@Override
public NumberInterface floor() {
String str = value.toPlainString();
int decimalIndex = str.indexOf('.');
if(decimalIndex != -1){
return new PreciseNumber(str.substring(0, decimalIndex));
}
return this;
}
@Override
public NumberInterface fractionalPart() {
String str = value.toPlainString();
int decimalIndex = str.indexOf('.');
if(decimalIndex != -1){
return new PreciseNumber(str.substring(decimalIndex + 1));
}
return ZERO;
}
@Override
public int intValue() {
return value.intValue();
}
@Override