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

This commit is contained in:
Danila Fedorin 2017-07-26 14:49:34 -07:00
commit 2074c11095
2 changed files with 16 additions and 1 deletions

View File

@ -29,7 +29,7 @@ public class NaiveNumber implements NumberInterface {
@Override
public int precision() {
return 4;
return 10;
}
@Override

15
src/org/nwapw/abacus/plugin/StandardPlugin.java Normal file → Executable file
View File

@ -80,6 +80,9 @@ public class StandardPlugin extends Plugin {
@Override
protected NumberInterface applyInternal(NumberInterface[] params) {
if(params[0].signum() == 0){
return (new NaiveNumber(1)).promoteTo(params[0].getClass());
}
NumberInterface factorial = params[0];
NumberInterface multiplier = params[0];
//It is necessary to later prevent calls of factorial on anything but non-negative integers.
@ -89,6 +92,18 @@ public class StandardPlugin extends Plugin {
return factorial;
}
});
System.out.println(getExpSeriesTerm(4, new NaiveNumber(3)));
}
/**
* Returns the nth term of the Taylor series (centered at 0) of e^x
* @param n the term required (n >= 0).
* @param x the real number at which the series is evaluated.
* @return
*/
private NumberInterface getExpSeriesTerm(int n, NumberInterface x){
return x.intPow(n).divide(this.getFunction("!").apply((new NaiveNumber(n)).promoteTo(x.getClass())));
}
}