Skip to content

Commit

Permalink
make rationalize default to use Int on Irrational (and Real) (#…
Browse files Browse the repository at this point in the history
…46656)

Co-authored-by: Lilith Orion Hafner <lilithhafner@gmail.com>
  • Loading branch information
MasonProtter and LilithHafner authored Dec 9, 2023
1 parent 649982a commit abeb68f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function rationalize(::Type{T}, x::Union{AbstractFloat, Rational}, tol::Real) wh
end
end
rationalize(::Type{T}, x::AbstractFloat; tol::Real = eps(x)) where {T<:Integer} = rationalize(T, x, tol)
rationalize(x::AbstractFloat; kvs...) = rationalize(Int, x; kvs...)
rationalize(x::Real; kvs...) = rationalize(Int, x; kvs...)
rationalize(::Type{T}, x::Complex; kvs...) where {T<:Integer} = Complex(rationalize(T, x.re; kvs...), rationalize(T, x.im; kvs...))
rationalize(x::Complex; kvs...) = Complex(rationalize(Int, x.re; kvs...), rationalize(Int, x.im; kvs...))
rationalize(::Type{T}, x::Rational; tol::Real = 0) where {T<:Integer} = rationalize(T, x, tol)
Expand Down
1 change: 1 addition & 0 deletions test/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ end
100798//32085
103993//33102
312689//99532 ]
@test rationalize(pi) === rationalize(BigFloat(pi))
end

@testset "issue #12536" begin
Expand Down

0 comments on commit abeb68f

Please sign in to comment.