Skip to content

correct safe integer range for bitwise ops#381

Merged
stephenamar-db merged 1 commit intomasterfrom
stephenamar-db/stack/int
May 14, 2025
Merged

correct safe integer range for bitwise ops#381
stephenamar-db merged 1 commit intomasterfrom
stephenamar-db/stack/int

Conversation

@stephenamar-db
Copy link
Copy Markdown
Collaborator

Fixes #317 #316 #315

@stephenamar-db stephenamar-db merged commit 982de09 into master May 14, 2025
6 checks passed
@stephenamar-db stephenamar-db deleted the stephenamar-db/stack/int branch May 14, 2025 20:28
// Constants for safe double-to-int conversion
// IEEE 754 doubles precisely represent integers up to 2^53, beyond which precision is lost
private val DOUBLE_MAX_SAFE_INTEGER = (1L << 53) - 1
private val DOUBLE_MIN_SAFE_INTEGER = -((1L << 53) - 1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be nice to have the same comments:

Integers can be safely represented as a Jsonnet number in the range [-2^53 + 1,2^53 - 1]. This is a direct consequence of IEEE754 spec, with the requirements that a safe integer is representable exactly, and cannot be produced by rounding any other integer to fit the IEEE-754 representation. See also, the JavaScript Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER, and Number.isSafeInteger definitions.

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

Labels

None yet

Projects

None yet

2 participants