diff --git a/Project.toml b/Project.toml index 7b4d0bd..3a8ad29 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "IrrationalConstants" uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" authors = ["JuliaMath"] -version = "0.2.3" +version = "0.2.4" [compat] julia = "1" diff --git a/src/macro.jl b/src/macro.jl index 0dc5056..12a66bc 100644 --- a/src/macro.jl +++ b/src/macro.jl @@ -135,5 +135,32 @@ function irrational(sym::Symbol, val::Union{Float64,Expr}, def::Union{Symbol,Exp @assert isa(big($esym), BigFloat) @assert Float64($esym) == Float64(big($esym)) @assert Float32($esym) == Float32(big($esym)) + + # https://github.com/JuliaLang/julia/pull/55886 removed these effects for generic `AbstractIrrational` subtypes + @static if isdefined(Base, :_throw_argument_error_irrational_to_rational_bigint) + function Base.Rational{$BigInt}(::$eT) + Base._throw_argument_error_irrational_to_rational_bigint() + end + end + @static if isdefined(Base, :_irrational_to_rational) + Base.@assume_effects :foldable function Base.Rational{T}(x::$eT) where {T<:Integer} + Base._irrational_to_rational(T, x) + end + end + @static if isdefined(Base, :_irrational_to_float) + Base.@assume_effects :foldable function (::Type{T})(x::$eT, r::RoundingMode) where {T<:Union{Float32,Float64}} + Base._irrational_to_float(T, x, r) + end + end + @static if isdefined(Base, :_rationalize_irrational) + Base.@assume_effects :foldable function Base.rationalize(::Type{T}, x::$eT; tol::Real=0) where {T<:Integer} + Base._rationalize_irrational(T, x, tol) + end + end + @static if isdefined(Base, :_lessrational) + Base.@assume_effects :foldable function Base.lessrational(rx::Rational, x::$eT) + Base._lessrational(rx, x) + end + end end end diff --git a/test/runtests.jl b/test/runtests.jl index d9a8bca..4ac2b8e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -255,3 +255,8 @@ end ) end end + +# issues #37 and #40 +@testset "slow comparisons" begin + @test iszero(@allocated(3.0 <= invsqrt2)) +end