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 IrrationalConstants and sinpi/cospi #40

Merged
merged 3 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 31 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: "Add the General registry via Git"
run: |
import Pkg
ENV["JULIA_PKG_SERVER"] = ""
Pkg.Registry.add("General")
shell: julia --color=yes {0}
- name: "Install CompatHelper"
run: |
import Pkg
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
version = "3"
Pkg.add(; name, uuid, version)
shell: julia --color=yes {0}
- name: "Run CompatHelper"
run: |
import CompatHelper
CompatHelper.main()
shell: julia --color=yes {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manifest.toml
12 changes: 8 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
name = "Tau"
uuid = "c544e3c2-d3e5-5802-ac44-44683f340e4a"
version = "0.2.0"
version = "0.3.0"
devmotion marked this conversation as resolved.
Show resolved Hide resolved

[deps]
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"

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

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]

[compat]
julia = "1"
24 changes: 17 additions & 7 deletions src/Tau.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
VERSION < v"0.7.0-beta2.199" && __precompile__()

module Tau

import IrrationalConstants

export tau, τ,
sintau, costau, modtau,
sinτ, cosτ, modτ

# Use overridden macro definition to define conversion methods for tau
Base.@irrational τ 6.28318530717958647692 (2 * big(pi))
# Definition of τ as irrational constant
const τ = IrrationalConstants.twoπ
const tau = τ

include("trig.jl")
const modτ = mod2pi
const modtau = modτ

# Trigonometric functions
sinτ(x) = sinpi(2 * x)
cosτ(x) = cospi(2 * x)

# Optimization for integers
sinτ(x::Integer) = zero(float(x))
cosτ(x::Integer) = one(float(x))

modtau(x) = Base.mod2pi(x)
const modτ = modtau
const sintau = sinτ
const costau = cosτ

end
102 changes: 0 additions & 102 deletions src/trig.jl

This file was deleted.

22 changes: 6 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
include("../src/Tau.jl")
using Main.Tau
VERSION < v"0.7.0-beta2.199" ? using Base.Test : using Test
using Tau
using Test

@testset "self-identity" begin
@test isa(tau, Irrational)
@test τ == τ
@test τ == tau
@test tau isa Irrational{:twoπ}
@test τ === τ
@test τ === tau
end

@testset "tau vs. 2pi" begin

@testset "symbols" begin
@test τ ≠ 2π # tau is Irrational, can't be equal to an AbstractFloat
@test 2π ≠ τ
Expand All @@ -29,13 +27,10 @@ end
@test Float64(Float32(tau)) == Float64(2 * Float32(pi))
@test BigFloat(tau) == 2 * BigFloat(pi)
end

end

@testset "sintau/costau" 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))))
Expand All @@ -50,11 +45,9 @@ end
@test @inferred(costau(z)) ≈ cospi(2 * z)
end
end

end

@testset "exact results for integer inputs" begin

@testset "real and complex values passed as integer types" begin
for T = (Int, Complex), x = -3:3
@test @inferred(sintau(T(x))) == zero(T)
Expand All @@ -68,11 +61,9 @@ end
@test @inferred(costau(T(x))) == one(T)
end
end

end

@testset "corner cases for abnormal inputs" begin

@testset "real values" begin
for x in (Inf, -Inf)
@test_throws DomainError sintau(x)
Expand All @@ -89,13 +80,12 @@ end
@test isequal(@inferred(costau(z)), cospi(2 * z))
end
end

end

# Adapted from julia/test/math.jl
@testset "type stability" begin
for T = (Int, Float32, Float64, BigFloat), f = (sintau, costau)
@test Base.return_types(f, Tuple{T}) == [T]
@test Base.return_types(f, Tuple{T}) == [float(T)]
@test Base.return_types(f, Tuple{Complex{T}}) == [Complex{float(T)}]
end
end
Expand Down