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

Add "missing" irrationals #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "IrrationalConstants"
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
authors = ["JuliaMath"]
version = "0.1.0"
version = "0.1.1"

[compat]
julia = "1"
Expand Down
53 changes: 31 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,36 @@
This package defines the following irrational constants:

```julia
twoπ # 2π
fourπ # 4π
halfπ # π / 2
quartπ # π / 4
invπ # 1 / π
twoinvπ # 2 / π
fourinvπ # 4 / π
inv2π # 1 / (2π)
inv4π # 1 / (4π)
sqrt2 # √2
sqrt3 # √3
sqrtπ # √π
sqrt2π # √2π
sqrt4π # √4π
sqrthalfπ # √(π / 2)
invsqrt2 # 1 / √2
invsqrt2π # 1 / √2π
loghalf # log(1 / 2)
logtwo # log(2)
logπ # log(π)
log2π # log(2π)
log4π # log(4π)
twoπ # 2π
fourπ # 4π
halfπ # π / 2
quartπ # π / 4
invπ # 1 / π
twoinvπ # 2 / π
fourinvπ # 4 / π
inv2π # 1 / (2π)
inv4π # 1 / (4π)
sqrt2 # √2
sqrt3 # √3
sqrtπ # √π
sqrt2π # √2π
sqrt4π # √4π
sqrthalfπ # √(π / 2)
sqrtquartπ # √(π / 4)
invsqrt2 # 1 / √2
invsqrt3 # 1 / √3
invsqrtπ # 1 / √π
invsqrt2π # 1 / √2π
invsqrt4π # 1 / √4π
invsqrthalfπ # 1 / √(π / 2)
invsqrtquartπ # 1 / √(π / 4)
Copy link
Contributor

@hyrodium hyrodium Apr 25, 2022

Choose a reason for hiding this comment

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

The git diff is a little illegible, so I think it would be better to add more spaces before # for when someone registers a new variable with a long name in another PR.

Suggested change
invsqrtquartπ # 1 / √(π / 4)
invsqrtquartπ # 1 / √(π / 4)

Or, it could be fine without aligning #.

loghalf # log(1 / 2)
logtwo # log(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be log2 like log3?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, log2 is a function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, I see.

log3 # log(3)
logπ # log(π)
log2π # log(2π)
log4π # log(4π)
loghalfπ # log(π / 2)
logquartπ # log(π / 4)
```

53 changes: 31 additions & 22 deletions src/IrrationalConstants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,37 @@ module IrrationalConstants
using Base: @irrational

export
twoπ, # 2π
fourπ, # 4π
halfπ, # π / 2
quartπ, # π / 4
invπ, # 1 / π
twoinvπ, # 2 / π
fourinvπ, # 4 / π
inv2π, # 1 / (2π)
inv4π, # 1 / (4π)
sqrt2, # √2
sqrt3, # √3
sqrtπ, # √π
sqrt2π, # √2π
sqrt4π, # √4π
sqrthalfπ, # √(π / 2)
invsqrt2, # 1 / √2
invsqrt2π, # 1 / √2π
loghalf, # log(1 / 2)
logtwo, # log(2)
logπ, # log(π)
log2π, # log(2π)
log4π # log(4π)
twoπ, # 2π
fourπ, # 4π
halfπ, # π / 2
quartπ, # π / 4
invπ, # 1 / π
twoinvπ, # 2 / π
fourinvπ, # 4 / π
inv2π, # 1 / (2π)
inv4π, # 1 / (4π)
sqrt2, # √2
sqrt3, # √3
sqrtπ, # √π
sqrt2π, # √2π
sqrt4π, # √4π
sqrthalfπ, # √(π / 2)
sqrtquartπ, # √(π / 4)
invsqrt2, # 1 / √2
invsqrt3, # 1 / √3
invsqrtπ, # 1 / √π
invsqrt2π, # 1 / √2π
invsqrt4π, # 1 / √4π
invsqrthalfπ, # 1 / √(π / 2)
invsqrtquartπ, # 1 / √(π / 4)
loghalf, # log(1 / 2)
logtwo, # log(2)
log3, # log(3)
logπ, # log(π)
log2π, # log(2π)
log4π, # log(4π)
loghalfπ, # log(π / 2)
logquartπ # log(π / 4)

include("stats.jl")

Expand Down
35 changes: 22 additions & 13 deletions src/stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@
@irrational inv2π 0.159154943091895335769 inv(2 * big(π))
@irrational inv4π 0.079577471545947667884 inv(4 * big(π))

@irrational sqrt2 1.4142135623730950488 sqrt(big(2))
@irrational sqrt3 1.7320508075688772935 sqrt(big(3))
@irrational sqrtπ 1.7724538509055160273 sqrt(big(π))
@irrational sqrt2π 2.5066282746310005024 sqrt(2 * big(π))
@irrational sqrt4π 3.5449077018110320546 sqrt(4 * big(π))
@irrational sqrthalfπ 1.2533141373155002512 sqrt(big(π) / 2)
@irrational sqrt2 1.4142135623730950488 sqrt(big(2))
@irrational sqrt3 1.7320508075688772935 sqrt(big(3))
@irrational sqrtπ 1.7724538509055160273 sqrt(big(π))
@irrational sqrt2π 2.5066282746310005024 sqrt(2 * big(π))
@irrational sqrt4π 3.5449077018110320546 sqrt(4 * big(π))
@irrational sqrthalfπ 1.2533141373155002512 sqrt(big(π) / 2)
@irrational sqrtquartπ 0.8862269254527580136 sqrt(big(π) / 4)

@irrational invsqrt2 0.7071067811865475244 inv(sqrt(big(2)))
@irrational invsqrt2π 0.3989422804014326779 inv(sqrt(2 * big(π)))
@irrational invsqrt2 0.7071067811865475244 inv(sqrt(big(2)))
@irrational invsqrt3 0.5773502691896257645 inv(sqrt(big(3)))
@irrational invsqrtπ 0.5641895835477562869 inv(sqrt(big(π)))
@irrational invsqrt2π 0.3989422804014326779 inv(sqrt(2 * big(π)))
@irrational invsqrt4π 0.2820947917738781435 inv(sqrt(4 * big(π)))
@irrational invsqrthalfπ 0.7978845608028653559 inv(sqrt(big(π) / 2))
@irrational invsqrtquartπ 1.1283791670955125739 inv(sqrt(big(π) / 4))

@irrational loghalf -0.6931471805599453094 log(inv(big(2)))
@irrational logtwo 0.6931471805599453094 log(big(2))
@irrational logπ 1.1447298858494001741 log(big(π))
@irrational log2π 1.8378770664093454836 log(2 * big(π))
@irrational log4π 2.5310242469692907930 log(4 * big(π))
@irrational loghalf -0.6931471805599453094 log(inv(big(2)))
@irrational logtwo 0.6931471805599453094 log(big(2))
@irrational log3 1.0986122886681096914 log(big(3))
@irrational logπ 1.1447298858494001741 log(big(π))
@irrational log2π 1.8378770664093454836 log(2 * big(π))
@irrational log4π 2.5310242469692907930 log(4 * big(π))
@irrational loghalfπ 0.4515827052894548647 log(big(π) / 2)
@irrational logquartπ -0.2415644752704904447 log(big(π) / 4)
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ end
@test isapprox(sqrt(2pi), sqrt2π)
@test isapprox(sqrt(4pi), sqrt4π)
@test isapprox(sqrt(pi/2), sqrthalfπ)
@test isapprox(sqrt(pi/4), sqrtquartπ)
@test isapprox(sqrt(1/2), invsqrt2)
@test isapprox(sqrt(1/3), invsqrt3)
@test isapprox(sqrt(1/pi), invsqrtπ)
@test isapprox(sqrt(1/(2pi)), invsqrt2π)
@test isapprox(sqrt(1/(4pi)), invsqrt4π)
@test isapprox(sqrt(2/pi), invsqrthalfπ)
@test isapprox(sqrt(4/pi), invsqrtquartπ)
end

@testset "log" begin
@test isapprox(log(1/2), loghalf)
@test isapprox(log(2), logtwo)
@test isapprox(log(3), log3)
@test isapprox(log(pi), logπ)
@test isapprox(log(2pi), log2π)
@test isapprox(log(4pi), log4π)
@test isapprox(log(pi/2), loghalfπ)
@test isapprox(log(pi/4), logquartπ)
end