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

Use mpfr_const_log2 #9

Merged
merged 6 commits into from
Oct 12, 2021
Merged

Use mpfr_const_log2 #9

merged 6 commits into from
Oct 12, 2021

Conversation

devmotion
Copy link
Member

@devmotion devmotion commented Sep 27, 2021

This PR changes the implementation of logtwo such that they use mpfr_const_log2. The resulting definition for BigFloat is very similar to https://github.com/JuliaLang/julia/blob/f5d944c453c2cbfee1a1765f0d6a5fc38597494e/base/mpfr.jl#L620-L624 but additionally it is possible to specify precision and rounding mode:

julia> @macroexpand Base.@irrational logtwo 0.6931471805599453094 log2
quote
    #= irrationals.jl:187 =#
    const logtwo = Base.Irrational{:logtwo}()
    #= irrationals.jl:188 =#
    begin
        #= irrationals.jl:173 =#
        function (Base.Base).BigFloat(::Base.Irrational{:logtwo}, var"#97#r"::(Base.MPFR).MPFRRoundingMode = (Base.MPFR).ROUNDING_MODE[]; precision = precision(Base.BigFloat))
            #= irrationals.jl:173 =#
            #= irrationals.jl:174 =#
            var"#95#c" = Base.BigFloat(; precision = precision)
            #= irrationals.jl:175 =#
            ccall(("mpfr_const_log2", :libmpfr), Base.Cint, (Base.Ref{Base.BigFloat}, (Base.MPFR).MPFRRoundingMode), var"#95#c", var"#97#r")
            #= irrationals.jl:177 =#
            return var"#95#c"
        end
    end
    #= irrationals.jl:189 =#
    (Base.Base).Float64(::Base.Irrational{:logtwo}) = begin
            #= irrationals.jl:189 =#
            0.6931471805599453
        end
    #= irrationals.jl:190 =#
    (Base.Base).Float32(::Base.Irrational{:logtwo}) = begin
            #= irrationals.jl:190 =#
            0.6931472f0
        end
    #= irrationals.jl:191 =#
    if Base.big(logtwo) isa Base.BigFloat
        nothing
    else
        Base.throw(Base.AssertionError("big(\$(Expr(:escape, :logtwo))) isa BigFloat"))
    end
    #= irrationals.jl:192 =#
    if Base.Float64(logtwo) == Base.Float64(Base.big(logtwo))
        nothing
    else
        Base.throw(Base.AssertionError("Float64(\$(Expr(:escape, :logtwo))) == Float64(big(\$(Expr(:escape, :logtwo))))"))
    end
    #= irrationals.jl:193 =#
    if Base.Float32(logtwo) == Base.Float32(Base.big(logtwo))
        nothing
    else
        Base.throw(Base.AssertionError("Float32(\$(Expr(:escape, :logtwo))) == Float32(big(\$(Expr(:escape, :logtwo))))"))
    end
end

@coveralls
Copy link

coveralls commented Sep 27, 2021

Pull Request Test Coverage Report for Build 1333223844

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 1333199438: 0.0%
Covered Lines: 0
Relevant Lines: 0

💛 - Coveralls

@codecov
Copy link

codecov bot commented Sep 27, 2021

Codecov Report

Merging #9 (78734de) into main (20348a2) will not change coverage.
The diff coverage is n/a.

❗ Current head 78734de differs from pull request most recent head 8849188. Consider uploading reports for the commit 8849188 to get more accurate results
Impacted file tree graph

@@    Coverage Diff    @@
##   main   #9   +/-   ##
=========================
=========================

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 20348a2...8849188. Read the comment docs.

@devmotion
Copy link
Member Author

Bump 🙂

@devmotion devmotion changed the title Use mpfr_const_log2 Use mpfr_const_log2 and mpfr_const_log10 Oct 12, 2021
@devmotion devmotion changed the title Use mpfr_const_log2 and mpfr_const_log10 Use mpfr_const_log2 Oct 12, 2021
@devmotion devmotion merged commit d226b95 into JuliaMath:main Oct 12, 2021
@devmotion devmotion deleted the dw/log2 branch October 12, 2021 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants