Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Branchless algorithm for RuntimeLong.toDouble.#5204

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sjrd merged 2 commits intoscala-js:mainfromsjrd:rt-long-to-double-much-simpler
Jul 9, 2025

Conversation

sjrd
Copy link
Member

@sjrdsjrd commentedJun 23, 2025
edited
Loading

It turns out the computation we did in the non-negative case also works for the negative case. The proof relies on elementary properties of the two's complement representation.

I don't know how I never saw this before. To make things worse, it seems that Kotlin and J2CL knew all along, and I never realized when skimming their implementations either.


As a second commit, we introduce code paths forsigned safe doubles, now that the conversions from signed longs to doubles is the same as the unsigned ones.

@sjrdsjrdforce-pushed thert-long-to-double-much-simpler branch from817e57a to8d55e54CompareJune 23, 2025 13:07
@sjrdsjrd requested a review fromgzm0June 23, 2025 13:08
@sjrdsjrdforce-pushed thert-long-to-double-much-simpler branch from8d55e54 to331baa8CompareJune 23, 2025 17:15
@sjrdsjrdforce-pushed thert-long-to-double-much-simpler branch 2 times, most recently from3d8e746 to2d4e635CompareJuly 2, 2025 07:56
Copy link
Contributor

@gzm0gzm0 left a comment

Choose a reason for hiding this comment

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

Nice!

sjrd added2 commitsJuly 9, 2025 00:11
It turns out the computation we did in the non-negative case alsoworks for the negative case. The proof relies on elementaryproperties of the two's complement representation.I don't know how I never saw this before. To make things worse, itseems that Kotlin and J2CL knew all along, and I never realizedwhen skimming through their implementations either.
Since conversions of signed longs to doubles is in fact no moreexpensive than the unsigned longs, we can take shorter paths forvalues that fit in the *signed* safe range.This applies to the conversions to string (including in thejavalib) and to float.It could also apply to signed division and remainder. However,benchmarks suggest that doing so makes it slower. The trouble isthat we then need a signed double-to-long conversion for theresult, and that appears to be slower than performing the 3 signadjustments.
@sjrdsjrdforce-pushed thert-long-to-double-much-simpler branch from2d4e635 tod24d1c3CompareJuly 8, 2025 22:18
@sjrdsjrdenabled auto-mergeJuly 8, 2025 22:31
@sjrdsjrd merged commitb9b6a6d intoscala-js:mainJul 9, 2025
3 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gzm0gzm0gzm0 approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@sjrd@gzm0

[8]ページ先頭

©2009-2025 Movatter.jp