Skip to content

Commit

Permalink
improve critical section exponent interpolation to log-frac-pow
Browse files Browse the repository at this point in the history
  • Loading branch information
Patashu committed Jul 23, 2022
1 parent 4269c74 commit 4237b41
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
7 changes: 5 additions & 2 deletions break_eternity.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3359,6 +3359,7 @@ var Decimal = /*#__PURE__*/function () {
var upper = 0; //basically, if we're between bases, we interpolate each bases' relevant values together
//then we interpolate based on what the fractional height is.
//accuracy could be improved by doing a non-linear interpolation (maybe), by adding more bases and heights (definitely) but this is AFAIK the best you can get without running some pari.gp or mathematica program to calculate exact values
//however, do note http://myweb.astate.edu/wpaulsen/tetcalc/tetcalc.html can do it for arbitrary heights but not for arbitrary bases (2, e, 10 present)

for (var i = 0; i < critical_headers.length; ++i) {
if (critical_headers[i] == base) {
Expand All @@ -3375,8 +3376,10 @@ var Decimal = /*#__PURE__*/function () {
}
}

var frac = height - Math.floor(height);
var result = lower * (1 - frac) + upper * frac;
var frac = height - Math.floor(height); //improvement - you get more accuracy (especially around 0.9-1.0) by doing log, then frac, then powing the result
//(we could pre-log the lookup table, but then fractional bases would get Weird)

var result = Math.pow(base, Math.log(lower) / Math.log(base) * (1 - frac) + Math.log(upper) / Math.log(base) * frac);
return result;
}
}]);
Expand Down
7 changes: 5 additions & 2 deletions break_eternity.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3357,6 +3357,7 @@ var Decimal = /*#__PURE__*/function () {
var upper = 0; //basically, if we're between bases, we interpolate each bases' relevant values together
//then we interpolate based on what the fractional height is.
//accuracy could be improved by doing a non-linear interpolation (maybe), by adding more bases and heights (definitely) but this is AFAIK the best you can get without running some pari.gp or mathematica program to calculate exact values
//however, do note http://myweb.astate.edu/wpaulsen/tetcalc/tetcalc.html can do it for arbitrary heights but not for arbitrary bases (2, e, 10 present)

for (var i = 0; i < critical_headers.length; ++i) {
if (critical_headers[i] == base) {
Expand All @@ -3373,8 +3374,10 @@ var Decimal = /*#__PURE__*/function () {
}
}

var frac = height - Math.floor(height);
var result = lower * (1 - frac) + upper * frac;
var frac = height - Math.floor(height); //improvement - you get more accuracy (especially around 0.9-1.0) by doing log, then frac, then powing the result
//(we could pre-log the lookup table, but then fractional bases would get Weird)

var result = Math.pow(base, Math.log(lower) / Math.log(base) * (1 - frac) + Math.log(upper) / Math.log(base) * frac);
return result;
}
}]);
Expand Down
7 changes: 5 additions & 2 deletions break_eternity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3363,6 +3363,7 @@
var upper = 0; //basically, if we're between bases, we interpolate each bases' relevant values together
//then we interpolate based on what the fractional height is.
//accuracy could be improved by doing a non-linear interpolation (maybe), by adding more bases and heights (definitely) but this is AFAIK the best you can get without running some pari.gp or mathematica program to calculate exact values
//however, do note http://myweb.astate.edu/wpaulsen/tetcalc/tetcalc.html can do it for arbitrary heights but not for arbitrary bases (2, e, 10 present)

for (var i = 0; i < critical_headers.length; ++i) {
if (critical_headers[i] == base) {
Expand All @@ -3379,8 +3380,10 @@
}
}

var frac = height - Math.floor(height);
var result = lower * (1 - frac) + upper * frac;
var frac = height - Math.floor(height); //improvement - you get more accuracy (especially around 0.9-1.0) by doing log, then frac, then powing the result
//(we could pre-log the lookup table, but then fractional bases would get Weird)

var result = Math.pow(base, Math.log(lower) / Math.log(base) * (1 - frac) + Math.log(upper) / Math.log(base) * frac);
return result;
}
}]);
Expand Down
2 changes: 1 addition & 1 deletion break_eternity.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": "break_eternity.js",
"version": "1.3.0",
"version": "1.3.1",
"description": "A Javascript numerical library to represent numbers as large as 10^^1e308 and as small as 10^-10^^1e308. Sequel to break_infinity.js, designed for incremental games.",
"main": "dist/break_eternity.js",
"module": "dist/break_eternity.esm.js",
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2570,6 +2570,7 @@ export default class Decimal {
//basically, if we're between bases, we interpolate each bases' relevant values together
//then we interpolate based on what the fractional height is.
//accuracy could be improved by doing a non-linear interpolation (maybe), by adding more bases and heights (definitely) but this is AFAIK the best you can get without running some pari.gp or mathematica program to calculate exact values
//however, do note http://myweb.astate.edu/wpaulsen/tetcalc/tetcalc.html can do it for arbitrary heights but not for arbitrary bases (2, e, 10 present)
for (let i = 0; i < critical_headers.length; ++i) {
if (critical_headers[i] == base) {
// exact match
Expand All @@ -2588,7 +2589,9 @@ export default class Decimal {
}
}
const frac = height - Math.floor(height);
const result = lower * (1 - frac) + upper * frac;
//improvement - you get more accuracy (especially around 0.9-1.0) by doing log, then frac, then powing the result
//(we could pre-log the lookup table, but then fractional bases would get Weird)
const result = Math.pow(base, (Math.log(lower)/Math.log(base)) * (1 - frac) + (Math.log(upper)/Math.log(base)) * frac );
return result;
}

Expand Down

0 comments on commit 4237b41

Please sign in to comment.