Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use Rational Numbers instead of the Epsilon Hack? #46

Closed
thebyrd opened this issue Dec 14, 2012 · 6 comments
Closed

Can we use Rational Numbers instead of the Epsilon Hack? #46

thebyrd opened this issue Dec 14, 2012 · 6 comments

Comments

@thebyrd
Copy link
Contributor

thebyrd commented Dec 14, 2012

https://github.com/LarryBattle/Ratio.js

@sjkaliski @ethanresnick

@sjkaliski
Copy link
Member

@davidbyrd11 I'm not sure about that library, and I don't think it's necessarily efficient (to the point at which it overcomes the error of floating points). However, I do agree we need a better solution the epsilon hack. Worth researching this weekend.

@LarryBattle
Copy link
Contributor

@sjkaliski In Javascript precision is lost for values passed +/- 9007199254740992. Everything after that becomes estimates.

Example: 10e30 %10 === 8

The only way to get passed this problem is to implement basic operations to support just numbers, but doing that would slow.

I think it would be cool if you could include Ratio.js inside your library but I'm not sure how well it fit.
If you find any issues with Ratio.js please raise an issue.

@Dakkers
Copy link
Contributor

Dakkers commented Sep 14, 2014

@sjkaliski @LarryBattle is this going anywhere? I don't necessarily think the epsilon hack is awful given the circumstances.

@LarryBattle
Copy link
Contributor

I looked through number.js code and couldn't find any good use cases for replacing the epsilon hack with ratio.js. The epsilon hack is basically this.

Math.abs(a-b) < numbers.EPSILON

Could someone provide me an example where lost of precision is currently a issue?
Possible examples

@Dakkers
Copy link
Contributor

Dakkers commented Sep 18, 2014

I don't think it's an issue, really. I'll just close this unless someone else has an issue with it.

@Dakkers Dakkers closed this as completed Sep 18, 2014
@devinjacobson
Copy link

It depends on what you want to concentrate on for the library in general, but there will be many things you cant do without a BigNumber, or some sort of fraction/rational number engine. i.e. I wrote a simple addition to the generator.js to generate a pascal triangle row just to play with the library, and can only get to row 55 accurately using the simple JS number precision. If there was a "factorized" number class for working with Integers, you could get much farther for certain things like this.
I have found the best way is to actually keep numbers in factorized rational form if you want to play with integers and go farther than what precision calculations generally takes you. <~2^55 is quite low.
C double gets to about 1000th row <~2^1000 with the same algorithm.

My primary interest is for playing with integer calculations and statistics. The library algorithms in general seem very efficient :)

generate.pascal = function (n, result) {
if (n < 1) return;
var s = 1;
var stemp = 1;
var ntemp = n;
result.push(s);
while (ntemp > 0){
s *= ntemp--;
s /= stemp++;
s = Math.round(s);
result.push(s);
}
return;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants