julia> uint8(0)-10xffjulia> uint32(0)-10xffffffffjulia> uint64(0)-10xffffffffffffffff
julia> uint8(0)-1-1julia> typeof(ans)Int64julia> uint32(0)-1-1julia> typeof(ans)Int64
julia> uint8(0)-int32(1)-1julia> typeof(ans)Int32julia> uint32(0)-int32(1)-1julia> typeof(ans)Int64julia> uint64(0)-int32(1)0xffffffffffffffff
julia> uint8(0)-1-1julia> typeof(ans)Int64julia> uint32(0)-1-1julia> typeof(ans)Int64
julia> uint64(0)-10xffffffffffffffff
julia> uint8(0)-1-1julia> typeof(ans)Int32
julia> uint32(0)-1-1julia> typeof(ans)Int64
julia> uint64(0)-10xffffffffffffffff
(gdb) p (short)0 - (unsigned short)1
$20 = -1
(gdb) p (int)0 - (unsigned int)1
$24 = 4294967295
(gdb) p (long long)0 - (unsigned int)1
$27 = -1
which is a little weird.
We should work out the promotion behavior of the sized integer types
first. Should we always preserve width, or try to give correct answers
by promoting to a larger type when possible?
Negation should be easy since it's unary. Maybe negation should always
preserve the type of its argument? But there is something to be said
for trying to give the numerically correct answer if possible. That's
what's going on in the alleged shit show; giving the right answer if
possible, otherwise doing something else.
This stuff:
julia> uint32(0)-int32(1)
-1
julia> uint64(0)-int32(1)
0xffffffffffffffff
will of course not change if Long!=Int64. Separate issue.
Random question: should we promote numbers to matrices so that "a\1"
inverts a matrix?
Unfortunately one() and zero() will still be necessary, in cases like this:
den(x::Int) = one(x)
But I guess they would be needed in fewer cases. Actually several of
the current uses of one and zero are not necessary.
In a case like this:
f = one(n)
for i = 2:n
f *= i
end
the one() is helpful since otherwise the type of f could change during the loop.
Otherwise the Long idea seems pretty good. It'd be nice if it had a
different name. Maybe we should call it Int and make Integer the
abstract type. Several times people have seen Int and thought of the C
type, which is a reasonable type to use, unlike our current Int type.
C seems to give these:
(gdb) p (short)0 - (unsigned short)1
$20 = -1
(gdb) p (int)0 - (unsigned int)1
$24 = 4294967295
(gdb) p (long long)0 - (unsigned int)1
$27 = -1
which is a little weird.
We should work out the promotion behavior of the sized integer types
first. Should we always preserve width, or try to give correct answers
by promoting to a larger type when possible?
Negation should be easy since it's unary. Maybe negation should always
preserve the type of its argument? But there is something to be said
for trying to give the numerically correct answer if possible. That's
what's going on in the alleged shit show; giving the right answer if
possible, otherwise doing something else.
This stuff:
julia> uint32(0)-int32(1)
-1
julia> uint64(0)-int32(1)
0xffffffffffffffff
will of course not change if Long!=Int64. Separate issue.
Random question: should we promote numbers to matrices so that "a\1"
inverts a matrix?
[A 11 B]
Unfortunately one() and zero() will still be necessary, in cases like this:
den(x::Int) = one(x)
But I guess they would be needed in fewer cases. Actually several of
the current uses of one and zero are not necessary.
In a case like this:
f = one(n)
for i = 2:n
f *= i
end
the one() is helpful since otherwise the type of f could change during the loop.
Otherwise the Long idea seems pretty good. It'd be nice if it had a
different name. Maybe we should call it Int and make Integer the
abstract type. Several times people have seen Int and thought of the C
type, which is a reasonable type to use, unlike our current Int type.