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

convert(Float64, ::BigInt) – rounding and corner cases #6365

Closed
StefanKarpinski opened this issue Apr 1, 2014 · 4 comments · Fixed by #10139
Closed

convert(Float64, ::BigInt) – rounding and corner cases #6365

StefanKarpinski opened this issue Apr 1, 2014 · 4 comments · Fixed by #10139
Labels
status:help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@StefanKarpinski
Copy link
Sponsor Member

See f04aa6f and https://gmplib.org/manual/Converting-Integers.html#Converting-Integers.

@JeffBezanson
Copy link
Sponsor Member

To expand on this a bit, the problem is that mpz_get_d always rounds towards zero, and it would be nice for the default conversion to use unbiased rounding instead (round to nearest, resolve ties to even).

@jiahao
Copy link
Member

jiahao commented Feb 9, 2015

In principle @simonbyrne's recent work on incorporating RoundingModes into Float64 constructors offers a simple resolution: simply define only Float64(::BigInt, RoundToZero) to work.

However, this issue is somewhat mind-bending: the edge cases here are when a BigInt is converted to Float64 where the granularity of Float64 is > 1.0 (the magnitude of the number must be ~1e16 or greater). I'm not sure if all the usual notions of rounding modes apply. What does "resolve ties to even" mean when eps(x) = 16384.0 ?

@simonbyrne
Copy link
Contributor

Ties to even is still well-defined: the even one is the number with the zero in last place of the significand (bits(x)[end]).

We could probably do this ourselves via an explicit branch if the returned absolute value is greater than maxintfloat?

@jiahao
Copy link
Member

jiahao commented Feb 9, 2015

That makes sense. (I didn't know maxintfloat existed!)

simonbyrne added a commit to simonbyrne/julia that referenced this issue Feb 9, 2015
simonbyrne added a commit to simonbyrne/julia that referenced this issue Feb 10, 2015
simonbyrne added a commit to simonbyrne/julia that referenced this issue Mar 10, 2015
simonbyrne added a commit to simonbyrne/julia that referenced this issue Mar 12, 2015
simonbyrne added a commit to simonbyrne/julia that referenced this issue Mar 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants