This is definitely possible, but integer operations will be a bit slower
since you'll have to do something like this:

bitstype 64 NullableInt


+(x::NullableInt, y::NullableInt) = ifelse(
        (reinterpret(Int,x) !== typemin(Int)) & (reinterpret(Int,y) !==
typemin(Int)),
        reinterpret(NullableInt, reinterpret(Int,x) + reinterpret(Int,y)),
        reinterpret(NullableInt, typemin(Int)),
    )


Fortunately, this is not as bad as it looks, but it's still a lot more work
than just doing an integer add instruction.

On Fri, Jul 24, 2015 at 2:42 PM, Scott Jones <[email protected]>
wrote:

> Maybe you could make your own 64-bit bitstype, which restricted values to
> integer values in the range that will fit in a Float64 (around -2^53 to
> 2^53).  Then you could be sure you didn't lose any information (give an
> InexactError if a value doesn't fit), and still allow for a NaN value, and
> fairly efficient computation.
>
> On Friday, July 24, 2015 at 2:04:33 PM UTC-4, Júlio Hoffimann wrote:
>>
>> Thank you all, that is what I thought, I will stick with plain Float64
>> for now.
>>
>> -Júlio
>>
>> 2015-07-24 10:59 GMT-07:00 Erik Schnetter <[email protected]>:
>>
>>> On Fri, Jul 24, 2015 at 1:09 PM, Júlio Hoffimann <[email protected]>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> Is there any definition of NaN for Integer types? Let's say I want to
>>>> create a matrix with some unspecified entries, that is entries marked
>>>> special. I am using NaN for Float64 but would like to make it work with
>>>> other types too. Suggestions?
>>>>
>>>
>>> There is no pre-defined integer nan equivalent.
>>>
>>> Option 1 (fast but unsafe): Pick a special int value that is rarely
>>> used, e.g. typemin(Int).
>>> Option 2 (works with all types, including Float64, and is safer): Use a
>>> nullable type. This might complicate your code and may slightly increase
>>> your memory usage.
>>>
>>> -erik
>>>
>>> --
>>> Erik Schnetter <[email protected]>
>>> http://www.perimeterinstitute.ca/personal/eschnetter/
>>>
>>
>>

Reply via email to