mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-05 02:09:53 -08:00
Merge branch 'master' of github.com:DanilaFe/abacus
This commit is contained in:
commit
fd87cb66a3
|
@ -182,7 +182,7 @@ public abstract class NumberInterface {
|
||||||
* Also, checks if the thread has been interrupted, and if so, throws
|
* Also, checks if the thread has been interrupted, and if so, throws
|
||||||
* an exception.
|
* an exception.
|
||||||
*
|
*
|
||||||
* @return the least integer bigger or equal to the number, if int can hold the value.
|
* @return the least integer bigger or equal to the number.
|
||||||
*/
|
*/
|
||||||
public final NumberInterface ceiling(){
|
public final NumberInterface ceiling(){
|
||||||
checkInterrupted();
|
checkInterrupted();
|
||||||
|
@ -192,7 +192,7 @@ public abstract class NumberInterface {
|
||||||
/**
|
/**
|
||||||
* Return the greatest integer less than or equal to the number.
|
* Return the greatest integer less than or equal to the number.
|
||||||
*
|
*
|
||||||
* @return the greatest integer smaller or equal the number, if int can hold the value.
|
* @return the greatest integer smaller or equal the number.
|
||||||
*/
|
*/
|
||||||
protected abstract NumberInterface floorInternal();
|
protected abstract NumberInterface floorInternal();
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ public abstract class NumberInterface {
|
||||||
* Also, checks if the thread has been interrupted, and if so, throws
|
* Also, checks if the thread has been interrupted, and if so, throws
|
||||||
* an exception.
|
* an exception.
|
||||||
*
|
*
|
||||||
* @return the greatest int smaller or equal to the number, if int can hold the value.
|
* @return the greatest int smaller than or equal to the number.
|
||||||
*/
|
*/
|
||||||
public final NumberInterface floor(){
|
public final NumberInterface floor(){
|
||||||
checkInterrupted();
|
checkInterrupted();
|
||||||
|
@ -216,7 +216,7 @@ public abstract class NumberInterface {
|
||||||
protected abstract NumberInterface fractionalPartInternal();
|
protected abstract NumberInterface fractionalPartInternal();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the fractional part of the number.
|
* Returns the fractional part of the number, specifically x - floor(x).
|
||||||
* Also, checks if the thread has been interrupted,
|
* Also, checks if the thread has been interrupted,
|
||||||
* and if so, throws an exception.
|
* and if so, throws an exception.
|
||||||
* @return the fractional part of the number.
|
* @return the fractional part of the number.
|
||||||
|
|
|
@ -113,19 +113,18 @@ public class PreciseNumber extends NumberInterface {
|
||||||
String str = value.toPlainString();
|
String str = value.toPlainString();
|
||||||
int decimalIndex = str.indexOf('.');
|
int decimalIndex = str.indexOf('.');
|
||||||
if (decimalIndex != -1) {
|
if (decimalIndex != -1) {
|
||||||
return new PreciseNumber(str.substring(0, decimalIndex));
|
NumberInterface floor = new PreciseNumber(str.substring(0, decimalIndex));
|
||||||
|
if(signum() == -1){
|
||||||
|
floor = floor.subtract(ONE);
|
||||||
|
}
|
||||||
|
return floor;
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NumberInterface fractionalPartInternal() {
|
public NumberInterface fractionalPartInternal() {
|
||||||
String str = value.toPlainString();
|
return this.subtractInternal(floorInternal());
|
||||||
int decimalIndex = str.indexOf('.');
|
|
||||||
if (decimalIndex != -1) {
|
|
||||||
return new PreciseNumber(str.substring(decimalIndex + 1));
|
|
||||||
}
|
|
||||||
return ZERO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -340,7 +340,8 @@ public class StandardPlugin extends Plugin {
|
||||||
protected boolean matchesParams(NumberInterface[] params) {
|
protected boolean matchesParams(NumberInterface[] params) {
|
||||||
return params.length == 2
|
return params.length == 2
|
||||||
&& !(params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0
|
&& !(params[0].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0
|
||||||
&& params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) == 0);
|
&& params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) == 0)
|
||||||
|
&& !(params[0].signum() == -1 && params[1].fractionalPart().compareTo(NaiveNumber.ZERO.promoteTo(params[1].getClass())) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -349,6 +350,13 @@ public class StandardPlugin extends Plugin {
|
||||||
return NaiveNumber.ZERO.promoteTo(params[0].getClass());
|
return NaiveNumber.ZERO.promoteTo(params[0].getClass());
|
||||||
else if (params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0)
|
else if (params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0)
|
||||||
return NaiveNumber.ONE.promoteTo(params[1].getClass());
|
return NaiveNumber.ONE.promoteTo(params[1].getClass());
|
||||||
|
//Detect integer bases:
|
||||||
|
if(params[0].fractionalPart().compareTo(fromInt(params[0].getClass(), 0)) == 0
|
||||||
|
&& FUNCTION_ABS.apply(params[0]).compareTo(fromInt(params[0].getClass(), Integer.MAX_VALUE)) < 0
|
||||||
|
&& FUNCTION_ABS.apply(params[1]).compareTo(fromInt(params[1].getClass(), 1)) >= 0){
|
||||||
|
NumberInterface[] newParams = {params[0], params[1].fractionalPart()};
|
||||||
|
return params[0].intPow(params[1].floor().intValue()).multiply(applyInternal(newParams));
|
||||||
|
}
|
||||||
return FUNCTION_EXP.apply(FUNCTION_LN.apply(FUNCTION_ABS.apply(params[0])).multiply(params[1]));
|
return FUNCTION_EXP.apply(FUNCTION_LN.apply(FUNCTION_ABS.apply(params[0])).multiply(params[1]));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user