Negating an unsigned effectively causes it to overflow.. it flips all bits 
(rather than the sign bit... which doesnt exist)

*julia> **bits(x)*

*"0000000000000000000000000000000000000000000000000000000000000100"*

*julia> **bits(-x)*

*"1111111111111111111111111111111111111111111111111111111111111100"*


So the start of the range you create is greater than typemax(Int64). 

*julia> **-x:x*

*0xfffffffffffffffc:0xfffffffffffffffb*

If you need negation, you need a signed integer, I think. 


Regards

-

Avik


On Wednesday, 3 June 2015 06:12:19 UTC+1, Pete Williams wrote:

> Hi, I'm not sure what the right way to form the range -X:X is when X is 
> Uint64.  It works as expected for smaller Uints
>
> *julia> **Q = uint(4)*
>
> *0x0000000000000004*
>
>
> *julia> **M = 0x4*
>
> *0x04*
>
>
> *julia> **typeof(Q)*
>
> *Uint64*
>
>
> *julia> **typeof(M)*
>
> *Uint8*
>
>
> *julia> **[-1*M:M]*
>
> *9-element Array{Int64,1}:*
>
> * -4*
>
> * -3*
>
> * -2*
>
> * -1*
>
> *  0*
>
> *  1*
>
> *  2*
>
> *  3*
>
> *  4*
>
>
> *julia> **[-1*Q:Q]*
>
> *ERROR: OverflowError()*
>
> * in vcat at range.jl:500*
>
> obviously I can make an Int64 copy of the Uint64 to fix this, but I'd like 
> to know if there is a more graceful way to do this.  Thanks.
>

Reply via email to