-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
make BigFloat(x::BigFloat) respect global precision (fix #20766) #29127
Conversation
8089f56
to
0e16cfc
Compare
I think |
I think it should be fine: |
@dpsanders @JeffreySarnoff What are your thoughts? |
Yes, definitely -- have been wanting for a long time! |
Ok, I'll defer to you folks on this, but then writing |
My slight preference to have |
@JeffBezanson When you say |
I meant |
👍 I am for that (I do the same with all my numeric types). @rfourquet We have |
That's not so obvious to me. What if some of the numbers are already BigFloats with more precision than the current global setting? Is the intent of Anyway, I think one thing we can all agree on is that it's not easy for everybody to be happy as long as this is a global setting. |
<and the change to a non-global setting is reasonably easy b'kuz the library's underlying struct used when we construct a BigFloat carries precision as a field> |
This works indeed, but this is nonetheless a gotcha. Say you use the setprecision(52) do
for x in A
z = BigFloat(x)
p = prevfloat(z) # now, z and p don't have the same precision if `x` was already a BigFloat :-/
@assert z == nextfloat(p) # ouch!
end
end
I wouldn't say it's the intent, but a possible consequence of the meaning I wish |
Ok, well, I will go away and defer to the more numerical folks here :) |
I don't see the gotcha. Let's separate concerns. To produce numbers of some same precision |
If you look at my last example, it's precicely a case where precision is mixed unintentionally ! i.e. For the record, I made this PR because I got caught by the "gotcha" of expecting that |
I think this is ready to merge, unless there are more objections. |
@rfourquet can you add an item to NEWS.md? |
OK, I will just wait for #29490 first, which prepares this file for 1.1.0. |
0e16cfc
to
fc7f70a
Compare
Thanks! |
This makes e.g.
BigFloat(BigFloat(1), 128)
have precision128
instead of the default256
.I'm not familiar with these questions, but this fix seems relatively sane to me. Currently there is no easy way (AFAIK) to create a
BigFloat
out of another one with a different precision, so allowing the documented API (BigFloat(x, prec)
) to do what it says seems to be a must. On the other hand, I don't know whether it's officially documented thatBigFloat(x)
creates aBigFloat
withprecision(BigFloat)
precision. But it's what we do for all other numbers, so I believe this is the most expected behavior to implement also forBigFloat
.As raised by @simonbyrne in the issue, there is also the question of
convert(BigFloat, x::BigFloat)
, which I didn't touch for now in this PR. But I think we don't have the expectation thatconvert
will create a new object (unlike for constructors), only that it returns an object of the destination type.It seems slighly breaking, but on the other hand, it was labeled as "bug" in the issue, so...