-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
float
, real
, complex
: impove docs, move docs inline, and add doctest examples
#19166
Conversation
a560d51
to
0663c7b
Compare
real{T<:Real}(::Type{T}) = T | ||
real{T<:Real}(::Type{Complex{T}}) = T | ||
""" | ||
real{R<:Real}(::Type{R}) |
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.
Should be more like:
real(T::Type)
Given a numeric type `T`,
return the corresponding `Real` type. For example, this returns
`R` for `T = Complex{R}`. Equivalent to `typeof(real(zero(T)))`.
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.
In fact, we should probably define a fallback method real(T::Type) = typeof(real(zero(T)))
.
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.
Do you think that a similar fallback should be defined for complex
and/or float
as well?
float(T::Type) = typeof(float(zero(T)))
complex(T::Type) = typeof(complex(zero(T)))
|
||
Convert real numbers or arrays to complex. `i` defaults to zero. | ||
|
||
complex{R<:Real}(::Type{R}) |
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.
Should be a separate docstring.
Gets an appropriate type that can represent a value of type `R` as a real number. | ||
For `R <: Complex{T}`, this function is equivalent to `real(T)`. | ||
|
||
```jldoctest |
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.
This seems like an excessive number of examples for such a simple function.
float
, real
, complex
: impove docs, move docs inline, and add doctest examplesfloat
, real
, complex
: impove docs, move docs inline, and add doctest examples
|
||
complex{T<:Real}(::Type{T}) = Complex{T} | ||
complex{T<:Real}(::Type{Complex{T}}) = Complex{T} | ||
Gets the type that represents the real part of a value of type `N`. |
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.
Gets -> returns.
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.
As a stylistic matter, we usually don't use the letter N
for type arguments. Usually it is T
or R,S
. That's why I suggested T
and Complex{R}
.
complex{T<:Real}(::Type{T}) = Complex{T} | ||
complex{T<:Real}(::Type{Complex{T}}) = Complex{T} | ||
Gets the type that represents the real part of a value of type `N`. | ||
e.g: for `N <: Complex{T}`, returns `T`. |
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.
Since Compex{T}
is concrete, <:
is superfluous. Just use N == Complex{T}
.
|
||
julia> complex(Int) | ||
Complex{Int64} | ||
``` |
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.
Two examples should suffice.
float(N::Type) | ||
|
||
Gets an appropriate type to represent a value of type `N` as a floating point value. | ||
For `N <: Complex{T}`, this function is equivalent to `float(T)`. |
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 second sentence is wrong, and in any case can probably be removed.
Float64 | ||
|
||
julia> float(Float16) | ||
Float16 |
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.
Two examples, say Int
, and Complex{Int}
, should suffice here.
251cb21
to
0b20e1b
Compare
""" | ||
real(N::Type) = typeof(real(zero(N))) | ||
real{R<:Real}(::Type{R}) = R | ||
real{R<:Real}(::Type{Complex{R}}) = R |
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 code should also keep the existing type parameter naming convention
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.
Dang it - missed this one!
LGTM. |
float
, real
, complex
: impove docs, move docs inline, and add doctest examplesfloat
, real
, complex
: impove docs, move docs inline, and add doctest examples
Travis failure seems unrelated. |
should obviously be squashed (at merge time if necessary) |
2374831
to
60a249e
Compare
Squash complete. |
(No need to manually squash: the github merge button can do the squash for you.) |
Fixes #18596 and #19113.
This PR:
Type
, which was absent before.jldoctest
examplesfloat
andcomplex
inline frombase/docs/helpdb/Base.jl
intobase/float.jl
andbase/complex.jl
--where the functions are defined--respectively.N.B: I haven't been able to verify that the doctests actually work...