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 docstring for zero function which input is type #37152

Merged
merged 3 commits into from
Aug 26, 2020

Conversation

AtsushiSakai
Copy link
Contributor

I found zero function can accept a type, not only a variable:

julia> zero(1.0)
0.0

julia> zero(Float64)
0.0

But, its docstring looks like missing later one, so I added it.

@sostock
Copy link
Contributor

sostock commented Aug 22, 2020

Note that the docstring already states that

x can also specify the type itself

@AtsushiSakai
Copy link
Contributor Author

Thanks for comment. Yes, but other similar functions looks like have its all function signatures:

julia/base/number.jl

Lines 247 to 248 in 3f373fa

one(x)
one(T::type)

julia/base/number.jl

Lines 284 to 285 in 3f373fa

oneunit(x::T)
oneunit(T::Type)

I think it should have it for consistency.

base/number.jl Outdated
@@ -223,6 +223,7 @@ map(f, x::Number, ys::Number...) = f(x, ys...)

"""
zero(x)
zero(T::type)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I think it's a little clearer if this is labeled as zero(::Type{<:Number})

Copy link
Contributor

Choose a reason for hiding this comment

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

There are types which are not <:Number but support zero, e.g. Dates.Day.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

True, but those are not hitting this particular method. It's probably okay to just call it ::Type then though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I change it to ::Type

@staticfloat
Copy link
Sponsor Member

Thanks @AtsushiSakai!

@staticfloat staticfloat merged commit 5da9691 into JuliaLang:master Aug 26, 2020
@AtsushiSakai AtsushiSakai deleted the fix_zero_func_docstring branch August 26, 2020 22:21
simeonschaub pushed a commit to simeonschaub/julia that referenced this pull request Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants