Skip to content

Commit

Permalink
Use IrrationalConstants and sinpi/cospi (#40)
Browse files Browse the repository at this point in the history
* Use `IrrationalConstants` and `sinpi`/`cospi`

* Bump to 1.0.0

Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>

* Update README

Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
  • Loading branch information
devmotion and giordano authored Apr 8, 2022
1 parent 4216830 commit d2fd316
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 141 deletions.
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 = "1.0.0"

[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"
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

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

[![travis][travis-img]](https://travis-ci.org/JuliaMath/Tau.jl)
[![appveyor][appveyor-img]](https://ci.appveyor.com/project/waldyrious/tau-jl)
[![codecov][codecov-img]](http://codecov.io/github/JuliaMath/Tau.jl)

[travis-img]: https://img.shields.io/travis/JuliaMath/Tau.jl/master.svg?label=Linux,%20macOS
[appveyor-img]: https://img.shields.io/appveyor/ci/waldyrious/tau-jl/master.svg?label=Windows
[codecov-img]: https://img.shields.io/codecov/c/github/JuliaMath/Tau.jl/master.svg?label=coverage
[![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)
[![codecov](https://img.shields.io/codecov/c/github/JuliaMath/Tau.jl/master.svg?label=coverage)](http://codecov.io/github/JuliaMath/Tau.jl)

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

```julia
using Tau
julia> using Tau

julia> tau === τ 2*pi
true

tau == τ 2*pi # => true
typeof(tau) # => Irrational{:τ}
julia> typeof(tau)
Irrational{:twoπ}
```

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

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

```julia
sintau(1//4) # => 1.0
costau(1//2) # => -1.0
julia> sintau(1//4)
1.0

julia> costau(1//2)
-1.0

julia> modtau(9*pi/4)
0.7853981633974481
```

Alternatively, one can use the Unicode aliases `sinτ`, `cosτ`, and `modτ`.

## The tau != 2pi inequality

When this package was first created, the equality `tau == 2pi` did hold true,
Expand Down
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

2 comments on commit d2fd316

@devmotion
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/58193

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" d2fd31636c7de3f5d0602f415a400f4079fdf4c8
git push origin v1.0.0

Please sign in to comment.