From 6346620332016a773b9b0c7beb3c504c16e0e584 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Thu, 23 Feb 2023 15:05:44 +0100 Subject: [PATCH 1/3] Add `cistau` (#46) * Add `cistau` * Fix some typos * More test fixes --- Project.toml | 2 +- src/Tau.jl | 16 ++++++++++++++-- test/runtests.jl | 12 +++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index ee8cbb6..a3472f5 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Tau" uuid = "c544e3c2-d3e5-5802-ac44-44683f340e4a" -version = "1.1.0" +version = "1.2.0" [deps] IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6" diff --git a/src/Tau.jl b/src/Tau.jl index a8256d9..af91e98 100644 --- a/src/Tau.jl +++ b/src/Tau.jl @@ -3,8 +3,8 @@ module Tau import IrrationalConstants export tau, τ, - sintau, costau, sincostau, modtau, - sinτ, cosτ, sincosτ, modτ + sintau, costau, sincostau, cistau, modtau, + sinτ, cosτ, sincosτ, cisτ, modτ # Definition of τ as irrational constant const τ = IrrationalConstants.twoπ @@ -25,6 +25,13 @@ function sincosτ(x) return sincospi(y) end end +cisτ(x::Real) = complex(reverse(sincosτ(x))...) +function cisτ(z::Complex) + sitau, cotau = sincosτ(z) + re_sitau, im_sitau = reim(sitau) + re_cotau, im_cotau = reim(cotau) + return complex(re_cotau - im_sitau, im_cotau + re_sitau) +end # Optimization for integers sinτ(x::Integer) = zero(float(x)) @@ -33,9 +40,14 @@ function sincosτ(x::Integer) y = float(x) return (zero(y), one(y)) end +function cisτ(x::Integer) + y = float(x) + return complex(one(y), zero(y)) +end const sintau = sinτ const costau = cosτ const sincostau = sincosτ +const cistau = cisτ end diff --git a/test/runtests.jl b/test/runtests.jl index edae625..0bc6c7f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -29,13 +29,14 @@ end end end -@testset "sintau/costau/sincostau" begin +@testset "sintau/costau/sincostau/cistau" begin @testset "approximate results for fractional inputs" begin @testset "real values" begin for T = (Float32, Float64), x = -3:0.1:3.0 @test @inferred(sintau(T(x))) ≈ T(sinpi(2 * parse(BigFloat, string(x)))) @test @inferred(costau(T(x))) ≈ T(cospi(2 * parse(BigFloat, string(x)))) @test @inferred(sincostau(T(x))) == (sintau(T(x)), costau(T(x))) + @test @inferred(cistau(T(x))) == costau(T(x)) + im * sintau(T(x)) end end @@ -45,6 +46,7 @@ end @test @inferred(sintau(z)) ≈ sinpi(2 * z) @test @inferred(costau(z)) ≈ cospi(2 * z) @test @inferred(sincostau(z)) == (sintau(z), costau(z)) + @test @inferred(cistau(z)) == costau(z) + im * sintau(z) end end end @@ -55,6 +57,7 @@ end @test @inferred(sintau(T(x))) == zero(T) @test @inferred(costau(T(x))) == one(T) @test @inferred(sincostau(T(x))) == (sintau(T(x)), costau(T(x))) + @test @inferred(cistau(T(x))) == costau(T(x)) + im * sintau(T(x)) end end @@ -63,6 +66,7 @@ end @test @inferred(sintau(T(x))) == sign(x) * zero(T) @test @inferred(costau(T(x))) == one(T) @test @inferred(sincostau(T(x))) == (sintau(T(x)), costau(T(x))) + @test @inferred(cistau(T(x))) == costau(T(x)) + im * sintau(T(x)) end end end @@ -73,10 +77,12 @@ end @test_throws DomainError sintau(x) @test_throws DomainError costau(x) @test_throws DomainError sincostau(x) + @test_throws DomainError cistau(x) end @test isequal(@inferred(sintau(NaN)), sinpi(NaN)) @test isequal(@inferred(costau(NaN)), cospi(NaN)) @test isequal(@inferred(sincostau(NaN)), (sintau(NaN), costau(NaN))) + @test isequal(@inferred(cistau(NaN)), costau(NaN) + im * sintau(NaN)) end @testset "complex values" begin @@ -85,6 +91,7 @@ end @test isequal(@inferred(sintau(z)), sinpi(2 * z)) @test isequal(@inferred(costau(z)), cospi(2 * z)) @test isequal(@inferred(sincostau(z)), (sintau(z), costau(z))) + @test isequal(@inferred(cistau(z)), costau(z) + im * sintau(z)) end end end @@ -98,6 +105,8 @@ end end @test Base.return_types(sincostau, Tuple{T}) == [Tuple{float(T), float(T)}] @test Base.return_types(sincostau, Tuple{Complex{T}}) == [Tuple{Complex{float(T)}, Complex{float(T)}}] + @test Base.return_types(cistau, Tuple{T}) == [Complex{float(T)}] + @test Base.return_types(cistau, Tuple{Complex{T}}) == [Complex{float(T)}] end end @@ -105,6 +114,7 @@ end @test sinτ === sintau @test cosτ === costau @test sincosτ === sincostau + @test cisτ === cistau end end From d00aa031ed056c7fd52c342a906627b3090c17b9 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Fri, 24 Feb 2023 16:10:29 +0100 Subject: [PATCH 2/3] Update Github actions (#48) --- .github/workflows/CI.yml | 4 ++-- .github/workflows/CompatHelper.yml | 13 +++++++++++++ .github/workflows/TagBot.yml | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c9b3285..15b36b6 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -32,6 +32,6 @@ jobs: - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v3 with: - file: lcov.info + files: lcov.info diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 39e1d95..7a9c79f 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -3,10 +3,23 @@ on: schedule: - cron: 0 0 * * * workflow_dispatch: +permissions: + contents: write + pull-requests: write jobs: CompatHelper: runs-on: ubuntu-latest steps: + - name: Check if Julia is already available in the PATH + id: julia_in_path + run: which julia + continue-on-error: true + - name: Install Julia, but only if it is not already available in the PATH + uses: julia-actions/setup-julia@v1 + with: + version: '1' + arch: ${{ runner.arch }} + if: steps.julia_in_path.outcome != 'success' - name: "Add the General registry via Git" run: | import Pkg diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml index f49313b..2bacdb8 100644 --- a/.github/workflows/TagBot.yml +++ b/.github/workflows/TagBot.yml @@ -4,6 +4,22 @@ on: types: - created workflow_dispatch: + inputs: + lookback: + default: 3 +permissions: + actions: read + checks: read + contents: write + deployments: read + issues: read + discussions: read + packages: read + pages: read + pull-requests: read + repository-projects: read + security-events: read + statuses: read jobs: TagBot: if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot' From acc9bacc25293b164b4656780f9e247dd953d4c1 Mon Sep 17 00:00:00 2001 From: David Widmann Date: Tue, 28 Feb 2023 17:29:33 +0100 Subject: [PATCH 3/3] Add documentation (#47) * Add documentation * Fix docstrings --- README.md | 10 ++++++++-- src/Tau.jl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a8b4965..842a841 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Irrational{:twoπ} Note: to input the τ character, type `\tau` then press Tab. -The tau variants of `sinpi`, `cospi`, and `mod2pi` are also defined: +The tau variants of `sinpi`, `cospi`, `sincospi`, `cispi`, and `mod2pi` are also defined: ```julia julia> sintau(1//4) @@ -38,11 +38,17 @@ julia> sintau(1//4) julia> costau(1//2) -1.0 +julia> sincostau(1//2) +(0.0, -1.0) + +julia> cistau(1//2) +-1.0 + 0.0im + julia> modtau(9*pi/4) 0.7853981633974481 ``` -Alternatively, one can use the Unicode aliases `sinτ`, `cosτ`, and `modτ`. +Alternatively, one can use the Unicode aliases `sinτ`, `cosτ`, `sincosτ`, `cisτ`, and `modτ`. ## The tau != 2pi inequality diff --git a/src/Tau.jl b/src/Tau.jl index af91e98..edc20fc 100644 --- a/src/Tau.jl +++ b/src/Tau.jl @@ -45,9 +45,54 @@ function cisτ(x::Integer) return complex(one(y), zero(y)) end +# Aliases const sintau = sinτ const costau = cosτ const sincostau = sincosτ const cistau = cisτ +# Documentation + +""" + sinτ(x) + sintau(x) + +Compute ``\\sin(\\tau x)`` more accurately than `sin(tau*x)`, especially for large `x`. + +See also: `costau`, `sincostau`. +""" +function sinτ end + +""" + cosτ(x) + costau(x) + +Compute ``\\cos(\\tau x)`` more accurately than `cos(tau*x)`, especially for large `x`. + +See also: `sintau`, `sincostau`. +""" +function cosτ end + +""" + sincosτ(x) + costau(x) + +Simultaneously compute `sintau(x)` and `costau(x)` (the sine and cosine of `tau*x`, +where `x` is in radians), returning a tuple `(sine, cosine)`. + +See also: `sintau`, `costau`. +""" +function sincosτ end + + +""" + cisτ(x) + cistau(x) + +Compute ``\\exp(\\tau i x)`` more accurately than `cis(tau*x)`, especially for large `x`. + +See also: `cis`, `sincostau`. +""" +function cisτ end + end