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 BigInt to Float conversions #10139

Merged
merged 1 commit into from
Mar 18, 2015
Merged

Conversation

simonbyrne
Copy link
Contributor

Fixes #6365


## checks if last bit is 0 or 1: used for IEEE rounding
is_ieee_even(x::Float64) = reinterpret(UInt64,x) & 1 == 0
is_ieee_even(x::Float32) = reinterpret(UInt32,x) & 1 == 0
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Maybe write these as is_ieee_even(x::Float64) = iseven(reinterpret(UInt64,x))?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have a slightly better solution.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Yes, generic reinterpret is much better!

@simonbyrne
Copy link
Contributor Author

I'm not sure what's causing the appveyor breakage.

@tkelman
Copy link
Contributor

tkelman commented Mar 11, 2015

https://ci.appveyor.com/project/StefanKarpinski/julia/build/1.0.3095/job/8abr5wkvv2exgyla looks a little scarier than the usual case of #10045, but I just built this branch (only one time for now) locally on win32 without seeing it. I'll restart the appveyor build.

@simonbyrne
Copy link
Contributor Author

Bump. Any thoughts?

cc: @StefanKarpinski

@StefanKarpinski
Copy link
Sponsor Member

Seems like a good thing to fix. Is there some potential downside? Otherwise just do it.

@simonbyrne
Copy link
Contributor Author

It will require some intermediate allocation of BigInts, but only if the original argument is larger than 2^53. I can't really see any way around this.

simonbyrne added a commit that referenced this pull request Mar 18, 2015
Fix BigInt to Float conversions
@simonbyrne simonbyrne merged commit 288ea08 into JuliaLang:master Mar 18, 2015
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.

convert(Float64, ::BigInt) – rounding and corner cases
3 participants