-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Move irrational constants to its own module #23427
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,10 +186,7 @@ export | |
NaN64, | ||
im, | ||
π, pi, | ||
e, eu, | ||
γ, eulergamma, | ||
catalan, | ||
φ, golden, | ||
ℯ, | ||
I, | ||
|
||
# Operators | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5299,7 +5299,7 @@ for (bdsdc, elty) in | |
u, &ldu, vt, &ldvt, | ||
q, iq, work, iwork, info) | ||
chklapackerror(info[]) | ||
d, e, u, vt, q, iq | ||
d, e_, u, vt, q, iq | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently we returned that mathematical constant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checked and |
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
""" | ||
Base.MathConstants | ||
|
||
Module containing the mathematical constants. | ||
See [`π`](@ref), [`ℯ`](@ref), [`γ`](@ref), [`φ`](@ref) and [`catalan`](@ref). | ||
""" | ||
module MathConstants | ||
|
||
export π, pi, ℯ, e, γ, eulergamma, catalan, φ, golden | ||
|
||
Base.@irrational π 3.14159265358979323846 pi | ||
Base.@irrational ℯ 2.71828182845904523536 exp(big(1)) | ||
Base.@irrational γ 0.57721566490153286061 euler | ||
Base.@irrational φ 1.61803398874989484820 (1+sqrt(big(5)))/2 | ||
Base.@irrational catalan 0.91596559417721901505 catalan | ||
|
||
# aliases | ||
""" | ||
π | ||
pi | ||
|
||
The constant pi. | ||
|
||
```jldoctest | ||
julia> pi | ||
π = 3.1415926535897... | ||
``` | ||
""" | ||
π, const pi = π | ||
|
||
""" | ||
ℯ | ||
e | ||
|
||
The constant ℯ. | ||
|
||
```jldoctest | ||
julia> ℯ | ||
ℯ = 2.7182818284590... | ||
``` | ||
""" | ||
ℯ, const e = ℯ | ||
|
||
""" | ||
γ | ||
eulergamma | ||
|
||
Euler's constant. | ||
|
||
```jldoctest | ||
julia> MathConstants.eulergamma | ||
γ = 0.5772156649015... | ||
``` | ||
""" | ||
γ, const eulergamma = γ | ||
|
||
""" | ||
φ | ||
golden | ||
|
||
The golden ratio. | ||
|
||
```jldoctest | ||
julia> MathConstants.golden | ||
φ = 1.6180339887498... | ||
``` | ||
""" | ||
φ, const golden = φ | ||
|
||
""" | ||
catalan | ||
|
||
Catalan's constant. | ||
|
||
```jldoctest | ||
julia> MathConstants.catalan | ||
catalan = 0.9159655941772... | ||
``` | ||
""" | ||
catalan | ||
|
||
# loop over types to prevent ambiguities for ^(::Number, x) | ||
for T in (Irrational, Rational, Integer, Number) | ||
Base.:^(::Irrational{:ℯ}, x::T) = exp(x) | ||
end | ||
|
||
Base.log(::Irrational{:ℯ}) = 1 # use 1 to correctly promote expressions like log(x)/log(ℯ) | ||
Base.log(::Irrational{:ℯ}, x::Number) = log(x) | ||
|
||
end # module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does it mean for this to be "the new default"? Default in what sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one being exported, and also
typeof(e)
has changed fromIrrational{:e}
toIrrational{:ℯ}
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, might be good to clarify that if you're willing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think my own wording is kinda weird too.