Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name = "IrrationalConstants"
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
authors = ["JuliaMath"]
version = "0.2.4"
version = "0.2.5"

[compat]
julia = "1"
julia = "1.10"

[extras]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# IrrationalConstants.jl

[![Build Status](https://github.com/JuliaMath/IrrationalConstants.jl/workflows/CI/badge.svg?branch=main)](https://github.com/JuliaMath/IrrationalConstants.jl/actions/workflows/CI.yml?query=branch%3Amain)
[![Build Status](https://github.com/JuliaMath/IrrationalConstants.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/JuliaMath/IrrationalConstants.jl/actions/workflows/CI.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/JuliaMath/IrrationalConstants.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/JuliaMath/IrrationalConstants.jl)
[![Coverage](https://coveralls.io/repos/github/JuliaMath/IrrationalConstants.jl/badge.svg?branch=main)](https://coveralls.io/github/JuliaMath/IrrationalConstants.jl?branch=main)

Expand Down
51 changes: 11 additions & 40 deletions src/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ Base.:<=(::T, ::T) where {T<:IrrationalConstant} = true
Base.hash(x::IrrationalConstant, h::UInt) = 3*objectid(x) - h
Base.round(x::IrrationalConstant, r::RoundingMode) = round(float(x), r)

# definitions for AbstractIrrational added in https://github.com/JuliaLang/julia/pull/34773
if VERSION < v"1.5.0-DEV.301"
Base.zero(::IrrationalConstant) = false
Base.zero(::Type{<:IrrationalConstant}) = false

Base.one(::IrrationalConstant) = true
Base.one(::Type{<:IrrationalConstant}) = true
end

# definition for AbstractIrrational added in https://github.com/JuliaLang/julia/pull/31068
if VERSION < v"1.2.0-DEV.337"
Base.inv(x::IrrationalConstant) = 1/x
end

# https://github.com/JuliaLang/julia/pull/50894
Base.typemin(::Type{T}) where {T<:IrrationalConstant} = T()
Base.typemax(::Type{T}) where {T<:IrrationalConstant} = T()
Expand Down Expand Up @@ -88,37 +74,22 @@ function irrational(sym::Symbol, val::Union{Float64,Expr}, def::Union{Symbol,Exp
esym = esc(sym)
qsym = esc(Expr(:quote, sym))
eT = esc(T)
bigconvert = if VERSION < v"1.1.0-DEV.683"
# support older Julia versions prior to https://github.com/JuliaLang/julia/pull/29157
isa(def,Symbol) ? quote
function Base.BigFloat(::$eT)
c = BigFloat()
bigconvert = if isa(def, Symbol)
# support older Julia versions prior to https://github.com/JuliaLang/julia/pull/51362
r = VERSION < v"1.12.0-DEV.78" ? :(Base.MPFR.ROUNDING_MODE[]) : :(Base.Rounding.rounding_raw(BigFloat))
quote
function Base.BigFloat(::$eT, r::Base.MPFR.MPFRRoundingMode=$r; precision=precision(BigFloat))
c = BigFloat(; precision=precision)
ccall(($(string("mpfr_const_", def)), :libmpfr),
Cint, (Ref{BigFloat}, Int32), c, Base.MPFR.ROUNDING_MODE[])
Cint, (Ref{BigFloat}, Base.MPFR.MPFRRoundingMode), c, r)
return c
end
end : quote
Base.BigFloat(::$eT) = $(esc(def))
end
else
# newer Julia versions
if isa(def, Symbol)
# support older Julia versions prior to https://github.com/JuliaLang/julia/pull/51362
r = VERSION < v"1.12.0-DEV.78" ? :(Base.MPFR.ROUNDING_MODE[]) : :(Base.Rounding.rounding_raw(BigFloat))
quote
function Base.BigFloat(::$eT, r::Base.MPFR.MPFRRoundingMode=$r; precision=precision(BigFloat))
c = BigFloat(; precision=precision)
ccall(($(string("mpfr_const_", def)), :libmpfr),
Cint, (Ref{BigFloat}, Base.MPFR.MPFRRoundingMode), c, r)
return c
end
end
else
quote
function Base.BigFloat(::$eT; precision=precision(BigFloat))
setprecision(BigFloat, precision) do
$(esc(def))
end
quote
function Base.BigFloat(::$eT; precision=precision(BigFloat))
setprecision(BigFloat, precision) do
$(esc(def))
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,9 @@ end
setprecision(f, BigFloat, prec)
end

# Prior to https://github.com/JuliaLang/julia/pull/40872 `setprecision(BigFloat, precision)` required precision >= 2
minprecision = VERSION < v"1.8.0-DEV.367" ? 2 : 1

# logtwo is the only constant defined based on an MPFR constant (similar to π, γ, catalan)
c = logtwo
for p ∈ minprecision:40
for p ∈ 1:40
@test (
irrational_to_big_float_with_rounding_mode_and_precision(c, RoundDown, p) < c <
irrational_to_big_float_with_rounding_mode_and_precision(c, RoundUp, p)
Expand Down