Two issues, but both require new type parameters to InfExtended, which could become:
InfExtended{T<:Real, C, S, F}
flag :: F
finitevalue :: T
...
end
Firstly, C for "compact" is a boolean. When false then F = InfFlag and flag represents whether the value is finite, positive infinity or negative infinity, as is the current implementation (or will be after #4). When true then F = Nothing and we use typemax(T) and typemin(T) to represent infinity in the finitevalue. This is "compact" because sizeof(InfExtended{T, true, ...}) == sizeof(T), at the expense of losing two finite values from T.
- What should the default
C be? Perhaps true whenever T is a bits type, and false otherwise?
- Make this default an overloadable function, so packages can define it for their own types?
- How can we let the user choose? Perhaps
InfExtended(T, :compact=>true)? Or just InfExtended(T, true)?
Secondly S for "signed" is a boolean. When true then both positive and negative infinity are allowed values. When false then only positive infinity is allowed. Hence S should be true whenever T is a signed type.
- Clearly the default for
S is whether or not T is a signed type.
- Do we ever let the user choose? I'm thinking no, but we could have a function
issigned(T) which controls its behaviour.
Two issues, but both require new type parameters to
InfExtended, which could become:InfExtended{T<:Real, C, S, F} flag :: F finitevalue :: T ... endFirstly,
Cfor "compact" is a boolean. WhenfalsethenF = InfFlagandflagrepresents whether the value is finite, positive infinity or negative infinity, as is the current implementation (or will be after #4). WhentruethenF = Nothingand we usetypemax(T)andtypemin(T)to represent infinity in thefinitevalue. This is "compact" becausesizeof(InfExtended{T, true, ...}) == sizeof(T), at the expense of losing two finite values fromT.Cbe? PerhapstruewheneverTis a bits type, andfalseotherwise?InfExtended(T, :compact=>true)? Or justInfExtended(T, true)?Secondly
Sfor "signed" is a boolean. Whentruethen both positive and negative infinity are allowed values. Whenfalsethen only positive infinity is allowed. HenceSshould be true wheneverTis a signed type.Sis whether or notTis a signed type.issigned(T)which controls its behaviour.