-
Notifications
You must be signed in to change notification settings - Fork 4
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 ishalfodd
function
#59
Changes from 4 commits
3798c03
77e1c50
2c22cfd
cf96fc4
2d8273b
21d121a
b0bc2e5
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
# Functions | ||
half, | ||
ishalfinteger, | ||
ishalfoddinteger, | ||
onehalf, | ||
twice | ||
|
||
|
@@ -561,6 +562,38 @@ | |
ishalfinteger(::AbstractIrrational) = false | ||
ishalfinteger(::Missing) = missing | ||
|
||
""" | ||
ishalfoddinteger(x) | ||
|
||
Test whether `x` is numerically equal to some half-odd-integer. | ||
|
||
# Examples | ||
|
||
```jldoctest | ||
julia> ishalfoddinteger(3.5) | ||
true | ||
|
||
julia> ishalfoddinteger(2) | ||
false | ||
|
||
julia> ishalfoddinteger(1//3) | ||
false | ||
``` | ||
""" | ||
ishalfoddinteger(x) = _isodd(twice(x)) | ||
ishalfoddinteger(x::Rational) = denominator(x) == 2 | ||
ishalfoddinteger(::Integer) = false | ||
ishalfoddinteger(::AbstractIrrational) = false | ||
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. I think this is not necessarily correct, because nothing prevents a user from defining an
Since we cannot add 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. Ah, I see. I added the method referring to the I now think we can just drop the method definition, and |
||
ishalfoddinteger(::Missing) = missing | ||
|
||
if VERSION ≥ v"1.7" | ||
sostock marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_isodd(x) = isodd(x) | ||
else | ||
_isodd(x::Real) = isodd(x) | ||
_isodd(n::Number) = isreal(n) && _isodd(real(n)) | ||
_isodd(x::AbstractFloat) = isinteger(x) && abs(x) ≤ maxintfloat(x) && _isodd(Integer(x)) | ||
end | ||
|
||
@static if VERSION ≥ v"1.7.0-DEV.263" | ||
Base.range_start_stop_length(start::T, stop::T, len::Integer) where T<:HalfInteger = | ||
Base._linspace(float(T), start, stop, len) | ||
|
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 I rename this function to
ishalfodd
, likeisinteger
andisodd
?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 don’t think it needs to be renamed (although it is quite long). To me,
ishalfoddinteger
seems clearer thanishalfodd
, but I’m fine with either name.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.
Thank you for the review! I named the function referring to the word "half-odd-integers" in the Wikipedia article.
But I now think consistency with
Base.odd
andBase.isinteger
has priority, so I will update the name. (I thinkishalfodd
is still clear enough.)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 don’t understand this. To me,
ishalfodd
seems consistent withBase.isodd
andishalfoddinteger
seems consistent withBase.isinteger
. Why do you think thatishalfoddinteger
is more consistent with both of them?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.
Sorry for confusing. I was just trying to clarify the pros and cons of these function names. The reason of
ishalfoddinteger
was just borrowing from the wikipedia article. I now changed the name toishalfodd
which is consistent with Base.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.
#59 (comment) was written before the commit b0bc2e5.