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

round methods missing in base #24021

Closed
ethomag opened this issue Oct 6, 2017 · 4 comments
Closed

round methods missing in base #24021

ethomag opened this issue Oct 6, 2017 · 4 comments
Labels
Hacktoberfest Good for Hacktoberfest participants maths Mathematical functions

Comments

@ethomag
Copy link
Contributor

ethomag commented Oct 6, 2017

Referencing this discourse entry

In Julia 0.6, there seems to be some round methods missing for basic types in Base:

julia> round(Float32, 1.0)
ERROR: MethodError: no method matching round(::Type{Float32}, ::Float64)
[...]
julia> round(Float64, 1.0)
ERROR: MethodError: no method matching round(::Type{Float64}, ::Float64)
[...]
julia> round(Complex64, Complex(0, 1.0))
ERROR: MethodError: no method matching round(::Type{Complex{Float32}}, ::Complex{Float64})
[...]

I interpreted @StefanKarpinski 's entry as a request to file an issue. I hope I did the right thing ?

@StefanKarpinski
Copy link
Member

Perfect, thank you!

@ararslan ararslan added Hacktoberfest Good for Hacktoberfest participants maths Mathematical functions labels Oct 6, 2017
@ggggggggg
Copy link
Contributor

ggggggggg commented Oct 6, 2017

This doesn't seem much nicer than Float16(round(1.0) but it does seem a bit more consistent with the docs. Here is an implementation

using Base.Test

myround(::Type{T}, x::AbstractFloat) where T<:Union{Real,Complex} = T(round(x))
myround(::Type{T}, x::AbstractFloat, r::RoundingMode) where T<:Union{Real,Complex} = T(round(x,r))
types = [Float16, Float32, Float64, BigFloat, Complex{Float64}, Int16, Int32, Int64, BigInt]
for T in types, S in types[1:4]
    @test myround(T, S(1.1))==1
    @test myround(T, S(1.1)) isa T
end

@BeastyBlacksmith
Copy link

BeastyBlacksmith commented Jun 20, 2019

I would like to add that I would like to see https://github.com/JuliaLang/julia/blob/master/base/floatfuncs.jl#L151-153 defined with x::Number, so that they work with Complex and other number-types (Measurements, Units, ... ).
I can make an additional PR, if that there is consent or it could be added to #30456

@adienes
Copy link
Contributor

adienes commented Sep 7, 2023

I believe this is closed by #50812, which also closes the associated PR #30456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Good for Hacktoberfest participants maths Mathematical functions
Projects
None yet
Development

No branches or pull requests

7 participants