1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 23:40:08 -08:00

Merge branch 'master' of github.com:DanilaFe/abacus

This commit is contained in:
Danila Fedorin 2017-08-07 14:27:29 -07:00
commit bdd39a7a8d
3 changed files with 19 additions and 12 deletions

View File

@ -182,7 +182,7 @@ public abstract class NumberInterface {
* Also, checks if the thread has been interrupted, and if so, throws
* 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(){
checkInterrupted();
@ -192,7 +192,7 @@ public abstract class NumberInterface {
/**
* 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();
@ -201,7 +201,7 @@ public abstract class NumberInterface {
* Also, checks if the thread has been interrupted, and if so, throws
* 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(){
checkInterrupted();
@ -216,7 +216,7 @@ public abstract class NumberInterface {
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,
* and if so, throws an exception.
* @return the fractional part of the number.

View File

@ -113,19 +113,18 @@ public class PreciseNumber extends NumberInterface {
String str = value.toPlainString();
int decimalIndex = str.indexOf('.');
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;
}
@Override
public NumberInterface fractionalPartInternal() {
String str = value.toPlainString();
int decimalIndex = str.indexOf('.');
if (decimalIndex != -1) {
return new PreciseNumber(str.substring(decimalIndex + 1));
}
return ZERO;
return this.subtractInternal(floorInternal());
}
@Override

View File

@ -340,7 +340,8 @@ public class StandardPlugin extends Plugin {
protected boolean matchesParams(NumberInterface[] params) {
return params.length == 2
&& !(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
@ -349,6 +350,13 @@ public class StandardPlugin extends Plugin {
return NaiveNumber.ZERO.promoteTo(params[0].getClass());
else if (params[1].compareTo(NaiveNumber.ZERO.promoteTo(params[0].getClass())) == 0)
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]));
}
});