fix(sync-rules): CAST(real AS INTEGER) should truncate towards zero like SQLite#694
Closed
sravan27 wants to merge 1 commit into
Closed
fix(sync-rules): CAST(real AS INTEGER) should truncate towards zero like SQLite#694sravan27 wants to merge 1 commit into
sravan27 wants to merge 1 commit into
Conversation
…ike SQLite The number->integer cast used BigInt(Math.floor(value)), which rounds towards negative infinity. SQLite truncates a REAL towards zero when casting to INTEGER, so CAST(-3.7 AS INTEGER) is -3, not -4. Switched to Math.trunc. Positive reals and string/bigint paths are unaffected. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 647e696 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Sravan Sridhar seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The number→integer path of
cast()usesBigInt(Math.floor(value)), which rounds towards −∞. SQLite truncates a REAL towards zero when casting to INTEGER, so the two diverge on every negative non-integer real:CAST(-3.7 AS INTEGER)-3-4CAST(-0.9 AS INTEGER)0-1CAST(-2.1 AS INTEGER)-2-3Since sync-rule expressions are evaluated client-side and must agree with the source database, an integer cast over a negative real (directly or via numeric coercion) can include/exclude rows differently on the client than on the server.
Fix
Use
Math.truncinstead ofMath.floor. Positive reals are unaffected (floor == trunc there), and the string/bigint cast paths are unchanged. Added regression tests; verified against the systemsqlite3as ground truth.🤖 Generated with Claude Code