-
-
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
bug in BigFloat trunc / floor / ceil / round #24041
Comments
Yes, I do think that would work. The assumption required is that you can correctly do the round/trunc/floor/ceil operation in the original type. That seems like a reasonable requirement. Once the value is correct in the source type, the value can simply be converted and rely on domain checking of convert, so the implementation is quite simple: $op(::Type{T}, x::Number) = convert(T, $op(x)) |
I would like to suggest a solution. Can't we convert BigFloat to AbstractFloat first and then, go for trunc? |
BigFloat is an implementation of AbstractFloat, so that conversion would do nothing. |
Ok, can you just tell me how can I test if I edit the code which I have cloned in my desktop? I want to try both the suggested one and mine. |
In simple cases like this you can just re-define the method at the REPL:
|
This has apparently been handled in #29157 julia> trunc(UInt8,BigFloat(255.5))
0xff |
The following error should not occur, as
trunc(255.5)
is 255 which is a legal UInt8:The same logic applies to the other casting functions.
A proper solution should be to perform the
round
/trunc
/floor
/ceil
in the source type, i.e. BigFloat and then cast to the target type and error if it doesn't fit correctly.The relevant code is:
julia/base/mpfr.jl
Lines 207 to 223 in c6899ec
The text was updated successfully, but these errors were encountered: