-
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 InfExtendedTime for TimeType support #10
Conversation
src/infextendedtime/comparison.jl
Outdated
@@ -0,0 +1,16 @@ | |||
Base.isfinite(x::InfExtendedTime) = x.flag == finite && isfinite(x.finitevalue) |
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 know that I really need that isfinite(x.finitevalue)
to be there.
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 suspect most of this code was copied from InfExtended
. It would probably be best to do some code generation rather than copy/paste. For example:
for InfExt in (InfExtended, InfExtendedTime)
@eval begin
Base.promote_rule(::Type{$InfExt{T}}, ::Type{$InfExt{S}}) where {T, S} = $InfExt(promote_type(T, S))
Base.promote_rule(::Type{$InfExt{T}}, ::Type{S}) where {T, S} = $InfExt(promote_type(T, S))
Base.promote_rule(::Type{$InfExt{T}}, ::Type{Infinite}) where T = $InfExt{T}
end
end
Base.isfinite(x::InfExtendedTime) = x.flag == finite && isfinite(x.finitevalue) | ||
Base.isinf(x::InfExtendedTime) = isposinf(x) || isneginf(x) | ||
Base.:(==)(x::InfExtendedTime, y::InfExtendedTime) = (isfinite(x) && isfinite(y)) ? x.finitevalue == y.finitevalue : x.flag == y.flag | ||
Base.hash(x::InfExtendedTime, h::UInt) = isfinite(x) ? hash(x.finitevalue, h) : hash(x.flag, h) |
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.
Currently wouldn't support hashing different infinities (e.g. InfExtended
vs. InfExtendedTime
) to the same result. I'm not sure what the desired behaviour is.
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.
Good point.
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'd like the hash to simply defer to whatever the true value is, i.e. the finitevalue
or PosInf
or NegInf
. It's fine that the infinite date has the same hash as the infinite number.
I guess this kind of breaks down the separated structure that #5 was looking for. Though I guess a few things could be moved into a more generic section. I'm thinking maybe this could be part of #5? |
79af179
to
cf810f0
Compare
Very true, maybe then it would good to add comments as to parts that were copied from |
Thanks for this, it looks really good. Please merge in the master branch --- I renamed the (badly thought through) |
If there is code that is sensible to generate together for both |
5f4b642
to
e82122b
Compare
Codecov Report
@@ Coverage Diff @@
## master #10 +/- ##
===========================================
+ Coverage 54.23% 67.40% +13.16%
===========================================
Files 13 18 +5
Lines 118 181 +63
===========================================
+ Hits 64 122 +58
- Misses 54 59 +5
Continue to review full report at Codecov.
|
3ff6ba2
to
29b02e0
Compare
Thanks :) |
It helps if I click the merge button! |
Alright here's a first pass at attempting to add TimeType support.
Tried to take #4 and #5 into account.
Closes #3