Skip to content

Commit

Permalink
making progress,,,
Browse files Browse the repository at this point in the history
  • Loading branch information
robert committed Aug 1, 2018
1 parent 237acc2 commit 580f79a
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

## Number.SE

*v1.0.144*
*v1.0.168*

Arithmetic library that uses string-encoded numbers to hanlde values much larger than Javascript's max safe integer.

Expand Down
133 changes: 121 additions & 12 deletions number.se.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions number.se.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "number.se",
"version": "1.0.144",
"version": "1.0.168",
"description": "Arithmetic library that uses string-encoded numbers to hanlde values much larger than Javascript's max safe integer",
"main": "number.se.js",
"scripts": {
Expand Down
92 changes: 90 additions & 2 deletions src/advanced_math.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,78 @@ Number.SE.prototype.powerOf = function(exp){
}
};

Number.SE.prototype.exp = function(){
var n = Number.SE.E().powerOf(this);
n.number = n.number.substr(0, Number.SE.PRECISION);
return n;
};

Number.SE.gamma = function(x) {
var p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028,
771.32342877765313, -176.61502916214059, 12.507343278686905,
-0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7
];
var g = 7;
if (x < 0.5) {
console.log("x < .5");
var piX = Math.PI * x;
console.log("piX ", piX);
var pixSin = Math.sin(piX);
console.log("pixSin ", pixSin);
var oneLessX = 1 - x;
console.log("oneLessX ", oneLessX);
var gamma1Lessx = Number.SE.gamma(oneLessX);
console.log("gamma1Lessx ", gamma1Lessx);
var denom = pixSin * gamma1Lessx;
console.log("denom ", denom);
return Math.PI / denom;
}
return "farts";
x -= 1;
var a = p[0];
var t = x + g + 0.5;
console.log("t", t);
for (var i = 1; i < p.length; i++) {
a += p[i] / (x + i);
console.log("a", a);
}
return Math.sqrt(2 * Math.PI) * Math.pow(t, x + 0.5) * Math.exp(-t) * a;
}

Number.SE.prototype.gamma = function(){
var p = [0.99999999999980993, 676.5203681218851, -1259.1392167224028,
771.32342877765313, -176.61502916214059, 12.507343278686905,
-0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7
];
var x = this;
var g = Number.SE(7);
if (x.lessThan(Number.SE(0.5))) {
console.log("x < .5");
var piX = Number.SE.Pi().multiplyBy(x);
console.log("piX ", piX.number);
var pixSin = piX.sin();
console.log("pixSin ", pixSin.number);
var oneLessX = Number.SE(1).subtract(x);
console.log("oneLessX ", oneLessX.number);
var gamma1Lessx = oneLessX.gamma();
console.log("gamma1Lessx ", gamma1Lessx.number);
var denom = pixSin.multiplyBy(gamma1Lessx)
console.log("denom ", denom.number);
return Number.SE.Pi().divideBy(denom);
}
return "farts";
x = x.subtract(1);
var a = Number.SE(p[0]);
var t = x.add(g).add(0.5);
console.log("t", t.number);
for (var i = 1; i < p.length; i++) {
a = a.add(Number.SE(p[i])).divideBy(x.add(i));
console.log("a", a.number);
}
return Number.SE(2).multiplyBy(Number.SE.Pi()).nthRoot(2).multiplyBy(t.powerOf(x.add(0.5))).multiplyBy(t.negate().exp()).multiplyBy(a);
//return Math.sqrt(2 * Math.PI) * Math.pow(t, x + 0.5) * Math.exp(-t) * a;
};

Number.SE.prototype.factorial = function(){
if(!this.isInt()){
throw new Error("factorialInt() can only calucalte the factorial of an integer");
Expand All @@ -39,8 +111,23 @@ Number.SE.prototype.factorial = function(){
}
};

Number.SE.cos = function(){
// https://math.stackexchange.com/questions/501660/is-there-a-way-to-get-trig-functions-without-a-calculator
Number.SE.prototype.tan = function(){
return this.sin().divideBy(this.cos());
};

Number.SE.prototype.cos = function(){
var cos = Number.SE(1); var add = false; var lastval = cos;
for(i=2;1;i+=2){
var num = this.powerOf(i);
var denom = Number.SE(i).factorial();
var quotient = num.divideBy(denom);
var method = add ? "add" : "subtract";
cos = cos[method](quotient);
if(lastval.equals(cos)) break;
lastval = cos;
add = !add;
}
return cos;
};

Number.SE.prototype.sin = function(){
Expand All @@ -53,6 +140,7 @@ Number.SE.prototype.sin = function(){
var method = add ? "add" : "subtract";
sin = sin[method](quotient);
if(lastval.equals(sin)) break;
console.log(sin.number);
lastval = sin;
add = !add;
}
Expand Down
19 changes: 14 additions & 5 deletions src/constructor.js

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Number.SE.prototype.lessThan = function(y){
};

Number.SE.prototype.equals = function(y){
if(!(y instanceof Number.SE)) y = new Number.SE(y).number;
return y===this.number;
if(!(y instanceof Number.SE)) y = new Number.SE(y);
return y.number===this.number;
};

Number.SE.prototype.floor = function(){
Expand All @@ -55,4 +55,16 @@ Number.SE.prototype.mod = function(divisor) {

Number.SE.prototype.negate = function(){
return this.isNegative() ? this.abs() : Number.SE("-"+this.number);
};

Number.SE.prototype.isInt = function(){
return !~this.number.indexOf(".");
};

Number.SE.prototype.toNumber = function(){
return Number(this.number);
};

Number.SE.prototype.toString = function(){
return this.number;
};

0 comments on commit 580f79a

Please sign in to comment.