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

Make InfExtendedReal a bitstype #13

Merged
merged 11 commits into from
Jun 14, 2020
Merged

Conversation

fchorney
Copy link
Contributor

closes #4

So here's an attempt at making InfExtendedReal a bitstype. Since a lot of the arithmetic and whatnot assumes it's working with a Real value, I added a x.val property accessor that will return the finite value or -+infinity. This seemed to be the easiest way to get InfExtendedReal into a bitstype without completely rewriting all the code for it.

That being said, I'm a little unsure how to fix the test changes where the @inferred tests were failing. I added the types that they should expect, but I'm not sure if thats the correct solution or if there is a better one.

Aside from that there were a couple of other minor changes to get the x.val accessor working properly. I might want to add more tests as well as I'm not sure everything is covered with the current set.

@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2020

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (f0f7037) to head (5e14363).
Report is 40 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##           master       #13       +/-   ##
============================================
+ Coverage   67.40%   100.00%   +32.59%     
============================================
  Files          18        18               
  Lines         181       189        +8     
============================================
+ Hits          122       189       +67     
+ Misses         59         0       -59     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -1,6 +1,6 @@
Base.isfinite(x::InfExtendedReal) = isfinite(x.val)
Base.isfinite(x::InfExtendedReal) = x.flag == FINITE && isfinite(x.finitevalue)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems strange to be storing non-finite values in a field called finitevalue

Copy link
Owner

Choose a reason for hiding this comment

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

Normally x.finitevalue will only ever be finite, unless the user does something like InfExtendedReal{Float64}(Inf).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I did the same thing in my dates PR as well. I didn't necessarily think it made sense to also check for finite in x.finitevalue. Guess it makes sense to remove it.

@@ -1 +1,10 @@
Base.show(io::IO, x::InfExtendedReal) = show(io, x.val)
function Base.show(io::IO, x::T) where {T<:InfExtendedReal}
value = isposinf(x) ? ∞ : isneginf(x) ? -∞ : x.finitevalue
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
value = isposinf(x) ?: isneginf(x) ? -: x.finitevalue
value = x.val

Comment on lines 14 to 18
"""
Since InfExtendedReal is a subtype of Real, and Infinite is also a subtype of real,
we can just use `x.val` to get either the finite value, or the infinite value. This will
make arithmetic much simpler.
"""
Copy link
Owner

Choose a reason for hiding this comment

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

Can you make this a comment? Else it pollutes the documentation for getproperty.

@cjdoris
Copy link
Owner

cjdoris commented Jun 10, 2020

The inferred tests are failing because the 2-argument form of @inferred was not available in v1.0.

@@ -1,4 +1,4 @@
Base.isfinite(x::InfExtendedReal) = x.flag == FINITE && isfinite(x.finitevalue)
Copy link
Owner

Choose a reason for hiding this comment

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

Change this back please. My previous comment was supposed to mean: normally x.finitevalue will be finite (and for things like Int this check can be optimised out anyway) but it's good to check in case we actually have InfExtendedReal{Float64}(Inf).

Copy link
Contributor Author

@fchorney fchorney Jun 10, 2020

Choose a reason for hiding this comment

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

Ah yes that's true. If you define it with the type specifically it will still be an InfExtendedReal rather than a plain Float64.

Edit: Also the page didn't update with your comment above when I was reading comments, so I completely missed it. Sorry!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That being said, would it make sense to modify the constructor to change InfExtendedReal{Float64}(Inf) to InfExtendedReal{Float64}(∞)?

Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps, I was wondering the same thing myself, but it's a separate issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that this constructor exists InfExtendedReal{T}(x::T) where {T<:Real} = new(FINITE, x) and also this function exists InfExtendedReal{T}(x::Real) where {T<:Real} = InfExtendedReal{T}(isinf(x) ? convert(Infinite, x) : convert(T, x)).

I can't seem to figure out under what circumstances the second function would ever trigger. I'm not sure it does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see, when T is Int it would trigger but not if T is say Float64

@fchorney
Copy link
Contributor Author

Opened this PR to add the 2 arg @inferred to Compat.jl JuliaLang/Compat.jl#706

@fchorney
Copy link
Contributor Author

Ok, I think this should be about ready to merge if anybody wants to give it a final check.

@cjdoris cjdoris merged commit 9250c38 into cjdoris:master Jun 14, 2020
@cjdoris
Copy link
Owner

cjdoris commented Jun 14, 2020

Thanks again! I'll release this as v0.2 soon.

@cjdoris
Copy link
Owner

cjdoris commented Jun 14, 2020

Oh and thanks for the extensive tests.

@fchorney
Copy link
Contributor Author

@cjdoris I'd like to do one more PR to clean everything up and consolidate things. Let me get that going, and when thats done we can release the v0.2 if thats ok with you

@cjdoris
Copy link
Owner

cjdoris commented Jun 15, 2020

I already released v0.2, but I'm happy to make v0.2.1. I was also planning to do a spring clean (and attend to some of the other issues I've been mulling over #6 #11 #14), but don't have time to do it for a little while so go ahead. Maybe make an issue to outline what you're planning?

@fchorney
Copy link
Contributor Author

ah ok no problemo. :) I'll throw an issue up and get it going

@fchorney fchorney deleted the fc/bitstype branch June 15, 2020 15:01
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.

InfExtended is not a bitstype
4 participants