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

Fix binding of +Infinity, -Infinity, -0, and extremely large number values #91

Merged
merged 4 commits into from
Nov 2, 2020

Conversation

jeremyBanks
Copy link
Contributor

@jeremyBanks jeremyBanks commented Nov 1, 2020

Closes #89

Fixes and adds tests the incorrect binding of +Infinity, -Infinity, -0, and extremely-large number values, by only binding to INTEGER for values which satisfy (Number.isSafeInteger(value) && !Object.is(value, -0)), instead of (Math.floor(value) === value).

In order to be preserve -0, we have to bind it as a REAL instead of an INTEGER like +0. As far as I can tell, this should be harmless.

A change in behaviour to call out: integer number values more massive than MAX_SAFE_INTEGER which could fit into an INTEGER will now be stored as REAL instead of INTEGER. I could go either way on this, but settled with this because you're usually not supposed to be treating values larger than MAX_SAFE_INTEGER as integers, even if they happen to fall on integer values.

If you want to maintain them as INTEGER, I think you could change the condition to something like (Number.isFinite(value) && !Object.is(value, -0) && Math.floor(value) === value && -9_223_372_036_854_775_808 <= value && value <= 9_223_372_036_854_775_807) instead.

Copy link
Owner

@dyedgreen dyedgreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for the PR! Looking pretty good so far. One thing I would like to change is to drop the -0 case.

SQLite serializes REAL values in tables in such a way that the -0 becomes a +0 regardless, so the check does not really do anything in practice. 😅

I left a couple of comments on how to structure the test cases as well. Happy to merge once those are addressed. 😅

src/db.ts Outdated Show resolved Hide resolved
test.ts Outdated Show resolved Hide resolved
test.ts Outdated Show resolved Hide resolved
test.ts Outdated Show resolved Hide resolved
test.ts Outdated Show resolved Hide resolved
test.ts Outdated Show resolved Hide resolved
@jeremyBanks jeremyBanks requested a review from dyedgreen November 2, 2020 04:26
@dyedgreen
Copy link
Owner

LGTM 😍

Thank you @jeremyBanks for flagging this issue and the quick fix!

@dyedgreen dyedgreen merged commit 78cf97b into dyedgreen:master Nov 2, 2020
@jeremyBanks jeremyBanks deleted the 89-infinities branch November 2, 2020 12:00
atsjj added a commit to atsjj/cotton that referenced this pull request Nov 20, 2020
* MySQL has been bumped to address the `v` prefix deprecation bug.
* Sqlite has been bumped to take advantages upstream, see dyedgreen/deno-sqlite#94
  and dyedgreen/deno-sqlite#91.
* Bumped Dockerfile deno base from `1.4.4` to `1.5.2`, which is the latest available
  container at the time of this PR.
atsjj added a commit to atsjj/cotton that referenced this pull request Nov 20, 2020
* MySQL has been bumped to address the `v` prefix deprecation bug.
* Sqlite has been bumped to take advantages upstream, see dyedgreen/deno-sqlite#94
  and dyedgreen/deno-sqlite#91.
* Bumped Dockerfile deno base from `1.4.4` to `1.5.2`, which is the latest available
  container at the time of this PR.
rahmanfadhil pushed a commit to rahmanfadhil/cotton that referenced this pull request Nov 21, 2020
* MySQL has been bumped to address the `v` prefix deprecation bug.
* Sqlite has been bumped to take advantages upstream, see dyedgreen/deno-sqlite#94
  and dyedgreen/deno-sqlite#91.
* Bumped Dockerfile deno base from `1.4.4` to `1.5.2`, which is the latest available
  container at the time of this PR.
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

Successfully merging this pull request may close these issues.

±Infinity are replaced with -9223372036854775808
2 participants