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

Roughnum overflow results in internal error #1470

Open
sorawee opened this issue Jul 25, 2019 · 9 comments
Open

Roughnum overflow results in internal error #1470

sorawee opened this issue Jul 25, 2019 · 9 comments

Comments

@sorawee
Copy link
Contributor

sorawee commented Jul 25, 2019

~1e+308 + ~1e+308

results in:

Non Pyret value: TypeError: Cannot read property 'throwDomainError' of undefined

This is the same problem as #819.

@blerner
Copy link
Member

blerner commented Jul 25, 2019

Jeeeeeeez. Now that I'm looking at js-numbers again, there are a lot more places that need errbacks. (And because JS allows function calls of incorrect arity, we never noticed......)

@blerner
Copy link
Member

blerner commented Jul 25, 2019

2bc5e66 is a first attempt at fixing this, but it's not thoroughly tested.

@sorawee
Copy link
Contributor Author

sorawee commented Jul 25, 2019

@blerner in the chart library I use a lot of these functions that you just add an extra argument. Should they be changed as well?

@blerner
Copy link
Member

blerner commented Jul 25, 2019

That's quite possible, yes. I think any of these functions could theoretically throw a numeric exception, so we need to start from all the exception-raising sites, and work outward to their callers, and outward from there, etc. until we get to either runtime.js or to another direct client of js-numbers. It looks like: ide.js, image-lib.js, world.js, the updated image libraries, d3-lib.js, d3-lib-list.js, plot-lib.js, plot-lib-list.js, chart-lib.js, and output-ui.js all potentially need fixing. (The worst culprit is toFixnum, which calls _integerDivideToFixnum, which is a makeIntegerBinop, which could call numerator and denominator and Roughnum.makeInstance, which each potentially use errbacks. I think none of those uses are live code when starting from toFixnum, but nevertheless we don't want mixed-arity calls...)

@ds26gte
Copy link
Contributor

ds26gte commented Jul 25, 2019

Are we still pushing fixes into the horizon branch these days?

@blerner
Copy link
Member

blerner commented Jul 25, 2019 via email

@blerner
Copy link
Member

blerner commented Jul 25, 2019 via email

@ds26gte
Copy link
Contributor

ds26gte commented Jul 29, 2019

Just saw your PR and tested it for the particular bug reported by @sorawee. You may ignore my other PR as yours subsumes it.

Here are my initial notes (which are easily fixable):

  • Make sure all calls to Roughnum.makeInstance use errbacks, (except for trivial stuff like Roughnum.makeInstance(1) which are known not to error).

  • BigInteger.prototype.toFixnum should call errbacks if returning JS Infinity.

  • To make integerDivideToFixnum work fault-tolerantly: makeIntegerBinop’s args should be allowed to take errbacks.

  • Some makeBignum calls could fail because we’re implicitly assuming fixnum-ness of the exponent part. While this may be reasonable assumption, should allow it take errbacks when it fails.

(I essentially zeroed in on all cases that use JS to produce a fixnum, either explicitly via a toFixnum or implicitly when supplying a JS result to Roughnum.makeInstance. The + and - failure brought up by @sorawee is an instance of the latter.)

I notice there seems to be a Pyret function called num-to-fixnum, but I couldn't actually use it in the IDE. Are we really supplying this to the user? It is apparently dropped (intentionally?) when populating the Pyret environment, but all the set-up (including Pyret-ish name) is present.

Is it possible to tag along my mods to your commit (is it a PR, I can't see it), or do I just create a separate branch based off your commit?

@blerner
Copy link
Member

blerner commented Jul 29, 2019

  • I think I just made a branch, so feel free to keep pushing onto that branch with additional changes.

  • I think we want to avoid any variadic function calls, so even trivial calls to makeInstance should take errbacks.

  • I'm pretty sure makeIntegerBinop's arguments can and do take errbacks, but double check that...

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

No branches or pull requests

3 participants