-
-
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
Converting between integer types #22235
Changes from 4 commits
25fa6f1
4a59f65
27d9634
ed37037
6efde61
fcd526e
9a8a73c
2243307
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 |
---|---|---|
|
@@ -41,9 +41,11 @@ end | |
|
||
""" | ||
clamp(x, lo, hi) | ||
clamp(T, x) | ||
|
||
Return `x` if `lo <= x <= hi`. If `x < lo`, return `lo`. If `x > hi`, return `hi`. Arguments | ||
are promoted to a common type. | ||
are promoted to a common type. If a type `T` is given, `lo` and `hi` are `typemin(T)` | ||
and `typemax(T)` respectively, and the result is converted to `T`. | ||
|
||
```jldoctest | ||
julia> clamp.([pi, 1.0, big(10.)], 2., 9.) | ||
|
@@ -59,6 +61,7 @@ clamp(x::X, lo::L, hi::H) where {X,L,H} = | |
convert(promote_type(X,L,H), lo), | ||
convert(promote_type(X,L,H), x))) | ||
|
||
clamp(::Type{T}, x) where {T} = clamp(x, typemin(T), typemax(T)) % T | ||
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. Maybe 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. Yes. It doesn't make sense for floats - the |
||
""" | ||
clamp!(array::AbstractArray, lo, hi) | ||
|
||
|
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.
I think that this would be more clear (i.e. more distinct) with two separate docstrings instead of trying to explain two things in the same docstring.
Something like: