-
-
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
merging itrunc into trunc, etc. #8728
Comments
Having opened the issue, let me take a stab.
The single-argument versions are Open question: how to make this dovetail with the two-argument form of |
👍 I don't mind so much keeping |
This makes sense. The typical signature would be:
which should handle cases like As far as definitions go: |
So what does the general signature |
Same as Admittedly, we probably don't need to define the general form for |
That's not really an answer. I mean something like
What do you replace "integer-valued" with when |
How's this:
|
I'm not sure that makes sense – e.g. which Float64 values have |
I guess we want to say something like "the value of type Also, I guess Something like this should work for integers: function round{T<:Integer}(::Type{T},x::Integer,d::Integer,b::Integer)
d <= 0 || throw(DomainError())
s = copysign(b>>1,x)
q = -d*b
convert(T,div(x+s,q)*q)
end |
Ok, now we're getting somewhere. I have also suspected that what we're doing may not be correctly rounded. It's actually kind of a strange operation to round a binary floating-point value to a number of decimal digits – number of decimal digits is a printing issue, not about values, really. |
I agree. We should probably add a big warning to the docs, and refer them to |
I wonder if we shouldn't deprecate rounding to various decimal places. |
I found using But I concur that it is a bit weird, and the documentation should have a big pointer to using |
You may be right – the hard work done by printing to ensure that the formatted output is minimal probably does guarantee that property. I'd like to convince myself slightly more thoroughly. Also, Float32 is the best thing ever for testing stuff like this since you can do exhaustive testing. |
The value returned should always print to the correct number of decimal places, provided the quantity The problem is that we don't strictly round in the correct direction: julia> @printf "%.60f" 8.315
8.314999999999999502620084967929869890213012695312500000000000
julia> round(8.315,2)
8.32
julia> @printf "%.2f" 8.315
8.31 Strictly speaking, |
Interestingly, python gets it right (both 2 and 3, even though they changed rounding behaviour): here is an interesting StackOverflow post. |
Reminds me of #3497 |
This issue needs a new title, or else can be closed. |
Closed by #9133. |
@simonbyrne observed that we could replace
itrunc(x)
withtrunc(Integer, x)
and similarly foriround
,iceil
andifloor
, making for a four-function reduction to the list of exports from Base. So far so good, but this brings up the issue of what these function generically mean, which is why I'm filing this issue for discussion.The text was updated successfully, but these errors were encountered: