-
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
InfExtended
is not a bitstype
#4
Comments
Something like this would allow the extended type to be a bitstype: using Infinity
@enum InfinityEnum::UInt8 finite neginf posinf
struct InfExtended2{T<:Real} <: Real
val::T
inf::InfinityEnum
InfExtended2{T}(x::T) where {T<:Real} = new(x, finite)
function InfExtended2{T}(x::Infinite) where {T<:Real}
if x == PosInf
new(x, posinf)
else
new(x, neginf)
end
end
end julia> isbitstype(InfExtended2{Int64})
true |
Yes, good idea --- the current implementation using I don't have time at the moment to do this, but feel free to send a PR. Let me know if you're planning to do this. If so, I think I like the following naming conventions. Also I think there was a bug in your inner constructor in the infinite case. This should work: @enum InfFlag::UInt8 finite neginf posinf
struct InfExtended{T<:Real} <: Real
flag :: InfFlag
finitevalue :: T
InfExtended{T}(x::T) where {T<:Real} = new{T}(isfinite, x)
InfExtended{T}(x::Infinite) where {T<:Real} = new{T}(x==PosInf ? isposinf : isneginf)
end |
I have just added |
Would the implementation be more so like: @enum InfFlag::UInt8 finite neginf posinf
struct InfExtended{T<:Real} <: Real
flag :: InfFlag
finitevalue :: T
InfExtended{T}(x::T) where {T<:Real} = new{T}(finite, x)
InfExtended{T}(x::Infinite) where {T<:Real} = new{T}(x==PosInf ? posinf : neginf)
end But also, wouldn't the second constructor end up making |
@fchorney your example looks correct. You are also correct in that the second constructor just has garbage for the |
ok that's kind of what I thought, since if the flag is infinite of any kind than we don't ever care about the value. |
Indeed. For example |
@omus Are you going to work on this? |
I'm not working on this currently |
It would be great if
InfExtended
was a bitstype so it could be used as a value in a parametric struct:The text was updated successfully, but these errors were encountered: