Skip to content

Commit

Permalink
Merge branch 'master' into dw/irrationalconstants
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Mar 1, 2023
2 parents dcd9eca + acc9bac commit 7bc3c8a
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version = "2.0.0"
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"

[compat]
IrrationalConstants = "0.1, 0.2"
IrrationalConstants = "0.2"
julia = "1"

[extras]
Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ IrrationalConstants.Twoπ

Note: to input the τ character, type `\tau` then press <kbd>Tab</kbd>.

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)
Expand All @@ -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

Expand Down
61 changes: 59 additions & 2 deletions src/Tau.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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π
Expand All @@ -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))
Expand All @@ -33,9 +40,59 @@ 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

# 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
12 changes: 11 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -98,13 +105,16 @@ 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

@testset "aliases" begin
@test sinτ === sintau
@test cosτ === costau
@test sincosτ === sincostau
@test cisτ === cistau
end
end

Expand Down

0 comments on commit 7bc3c8a

Please sign in to comment.