Skip to content

Commit d2fd316

Browse files
devmotiongiordano
andauthored
Use IrrationalConstants and sinpi/cospi (#40)
* Use `IrrationalConstants` and `sinpi`/`cospi` * Bump to 1.0.0 Co-authored-by: Mosè Giordano <[email protected]> * Update README Co-authored-by: Mosè Giordano <[email protected]>
1 parent 4216830 commit d2fd316

File tree

7 files changed

+81
-141
lines changed

7 files changed

+81
-141
lines changed

.github/workflows/CompatHelper.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CompatHelper
2+
on:
3+
schedule:
4+
- cron: 0 0 * * *
5+
workflow_dispatch:
6+
jobs:
7+
CompatHelper:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: "Add the General registry via Git"
11+
run: |
12+
import Pkg
13+
ENV["JULIA_PKG_SERVER"] = ""
14+
Pkg.Registry.add("General")
15+
shell: julia --color=yes {0}
16+
- name: "Install CompatHelper"
17+
run: |
18+
import Pkg
19+
name = "CompatHelper"
20+
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
21+
version = "3"
22+
Pkg.add(; name, uuid, version)
23+
shell: julia --color=yes {0}
24+
- name: "Run CompatHelper"
25+
run: |
26+
import CompatHelper
27+
CompatHelper.main()
28+
shell: julia --color=yes {0}
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Manifest.toml

Project.toml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
name = "Tau"
22
uuid = "c544e3c2-d3e5-5802-ac44-44683f340e4a"
3-
version = "0.2.0"
3+
version = "1.0.0"
4+
5+
[deps]
6+
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6"
7+
8+
[compat]
9+
IrrationalConstants = "0.1"
10+
julia = "1"
411

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

815
[targets]
916
test = ["Test"]
10-
11-
[compat]
12-
julia = "1"

README.md

+18-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
<div align="center"><img src="https://rawgit.com/JuliaMath/Tau.jl/master/tau-2pi.svg" width="300"/></div><br/><br/>
44

5-
[![travis][travis-img]](https://travis-ci.org/JuliaMath/Tau.jl)
6-
[![appveyor][appveyor-img]](https://ci.appveyor.com/project/waldyrious/tau-jl)
7-
[![codecov][codecov-img]](http://codecov.io/github/JuliaMath/Tau.jl)
8-
9-
[travis-img]: https://img.shields.io/travis/JuliaMath/Tau.jl/master.svg?label=Linux,%20macOS
10-
[appveyor-img]: https://img.shields.io/appveyor/ci/waldyrious/tau-jl/master.svg?label=Windows
11-
[codecov-img]: https://img.shields.io/codecov/c/github/JuliaMath/Tau.jl/master.svg?label=coverage
5+
[![CI](https://github.com/JuliaMath/Tau.jl/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/JuliaMath/Tau.jl/actions/workflows/CI.yml?query=branch%3Amaster)
6+
[![codecov](https://img.shields.io/codecov/c/github/JuliaMath/Tau.jl/master.svg?label=coverage)](http://codecov.io/github/JuliaMath/Tau.jl)
127

138
This [Julia](https://github.com/JuliaLang/julia) [package](http://pkg.julialang.org/)
149
defines the [Tau](http://www.tauday.com/tau-manifesto) constant
@@ -23,21 +18,32 @@ tau ≈ 2*pi
2318
After installing this package with `Pkg.add("Tau")`, it can be used as follows:
2419

2520
```julia
26-
using Tau
21+
julia> using Tau
22+
23+
julia> tau === τ 2*pi
24+
true
2725

28-
tau == τ 2*pi # => true
29-
typeof(tau) # => Irrational{:τ}
26+
julia> typeof(tau)
27+
Irrational{:twoπ}
3028
```
3129

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

3432
The tau variants of `sinpi`, `cospi`, and `mod2pi` are also defined:
3533

3634
```julia
37-
sintau(1//4) # => 1.0
38-
costau(1//2) # => -1.0
35+
julia> sintau(1//4)
36+
1.0
37+
38+
julia> costau(1//2)
39+
-1.0
40+
41+
julia> modtau(9*pi/4)
42+
0.7853981633974481
3943
```
4044

45+
Alternatively, one can use the Unicode aliases `sinτ`, `cosτ`, and `modτ`.
46+
4147
## The tau != 2pi inequality
4248

4349
When this package was first created, the equality `tau == 2pi` did hold true,

src/Tau.jl

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
VERSION < v"0.7.0-beta2.199" && __precompile__()
2-
31
module Tau
2+
3+
import IrrationalConstants
4+
45
export tau, τ,
56
sintau, costau, modtau,
67
sinτ, cosτ, modτ
78

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

12-
include("trig.jl")
13+
const modτ = mod2pi
14+
const modtau = modτ
15+
16+
# Trigonometric functions
17+
sinτ(x) = sinpi(2 * x)
18+
cosτ(x) = cospi(2 * x)
19+
20+
# Optimization for integers
21+
sinτ(x::Integer) = zero(float(x))
22+
cosτ(x::Integer) = one(float(x))
1323

14-
modtau(x) = Base.mod2pi(x)
15-
const modτ = modtau
24+
const sintau = sinτ
25+
const costau = cosτ
1626

1727
end

src/trig.jl

-102
This file was deleted.

test/runtests.jl

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
include("../src/Tau.jl")
2-
using Main.Tau
3-
VERSION < v"0.7.0-beta2.199" ? using Base.Test : using Test
1+
using Tau
2+
using Test
43

54
@testset "self-identity" begin
6-
@test isa(tau, Irrational)
7-
@test τ == τ
8-
@test τ == tau
5+
@test tau isa Irrational{:twoπ}
6+
@test τ === τ
7+
@test τ === tau
98
end
109

1110
@testset "tau vs. 2pi" begin
12-
1311
@testset "symbols" begin
1412
@test τ 2π # tau is Irrational, can't be equal to an AbstractFloat
1513
@test 2π τ
@@ -29,13 +27,10 @@ end
2927
@test Float64(Float32(tau)) == Float64(2 * Float32(pi))
3028
@test BigFloat(tau) == 2 * BigFloat(pi)
3129
end
32-
3330
end
3431

3532
@testset "sintau/costau" begin
36-
3733
@testset "approximate results for fractional inputs" begin
38-
3934
@testset "real values" begin
4035
for T = (Float32, Float64), x = -3:0.1:3.0
4136
@test @inferred(sintau(T(x))) T(sinpi(2 * parse(BigFloat, string(x))))
@@ -50,11 +45,9 @@ end
5045
@test @inferred(costau(z)) cospi(2 * z)
5146
end
5247
end
53-
5448
end
5549

5650
@testset "exact results for integer inputs" begin
57-
5851
@testset "real and complex values passed as integer types" begin
5952
for T = (Int, Complex), x = -3:3
6053
@test @inferred(sintau(T(x))) == zero(T)
@@ -68,11 +61,9 @@ end
6861
@test @inferred(costau(T(x))) == one(T)
6962
end
7063
end
71-
7264
end
7365

7466
@testset "corner cases for abnormal inputs" begin
75-
7667
@testset "real values" begin
7768
for x in (Inf, -Inf)
7869
@test_throws DomainError sintau(x)
@@ -89,13 +80,12 @@ end
8980
@test isequal(@inferred(costau(z)), cospi(2 * z))
9081
end
9182
end
92-
9383
end
9484

9585
# Adapted from julia/test/math.jl
9686
@testset "type stability" begin
9787
for T = (Int, Float32, Float64, BigFloat), f = (sintau, costau)
98-
@test Base.return_types(f, Tuple{T}) == [T]
88+
@test Base.return_types(f, Tuple{T}) == [float(T)]
9989
@test Base.return_types(f, Tuple{Complex{T}}) == [Complex{float(T)}]
10090
end
10191
end

0 commit comments

Comments
 (0)