Skip to content

Commit d3c26b7

Browse files
authored
Extend Base.rationalize instead of defining new function (#56793)
#55886 accidentally created a new function `Base.MathConstants.rationalize` instead of extending `Base.rationalize`, which is the reason why `Base.rationalize(Int, π)` isn’t constant-folded in Julia 1.10 and 1.11: ``` julia> @Btime rationalize(Int,π); 1.837 ns (0 allocations: 0 bytes) # v1.9: constant-folded 88.416 μs (412 allocations: 15.00 KiB) # v1.10: not constant-folded ``` This PR fixes that. It should probably be backported to 1.10 and 1.11.
1 parent 82daca2 commit d3c26b7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/mathconstants.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ end
2929
Base.@assume_effects :foldable function (::Type{T})(x::_KnownIrrational, r::RoundingMode) where {T<:Union{Float32,Float64}}
3030
Base._irrational_to_float(T, x, r)
3131
end
32-
Base.@assume_effects :foldable function rationalize(::Type{T}, x::_KnownIrrational; tol::Real=0) where {T<:Integer}
32+
Base.@assume_effects :foldable function Base.rationalize(::Type{T}, x::_KnownIrrational; tol::Real=0) where {T<:Integer}
3333
Base._rationalize_irrational(T, x, tol)
3434
end
3535
Base.@assume_effects :foldable function Base.lessrational(rx::Rational, x::_KnownIrrational)

0 commit comments

Comments
 (0)