-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
type stability of integer types under addition? #9162
Comments
Fixed in #8420. It was a big change. |
Not sure if I would call it "fixed" so much as changed. The old behavior was quite intentional. |
But it was never on the list of features users loved about Julia. |
At least, we got many complaints about the behaviour and no praise. |
True enough, @StefanKarpinski. It's not like it was without merit, it's just that the balance seems to favor the current choice. |
Let's wait and see how many reactions we get on the new behavior, shall we? |
Wow. This essentially removes C's "integer promotion" from Julia. That should definitively go into the 0.4 release notes. I think it also deserves a separate announcement to the list. Now -- what is the result of |
It's already in NEWS.md. I completely agree it's a big change, but overall I've been quite surprised about how little trouble it has caused. There is promotion in cases where the two types differ. You're running 0.4, right? Just try the cases you wonder about (this was merged more than a month ago). |
julia> 0x1 + 0x1
0x02
julia> UInt(1) + 1
0x0000000000000002 Unfortunately when choosing whether |
|
|
Returning We could also go the safe road: disallow automatic conversions between signed an unsigned types. In this case, we'd need a good syntax for unsigned integer literals, such as e.g. |
I think I agree with Erik here. In some of the grisu code and SuffixArrays, On Wed, Nov 26, 2014 at 2:30 PM, Erik Schnetter [email protected]
|
Yeah, that's the reason it is the way it is now. |
Mixing precisions and signs is something of a minefield. julia> 0x1 + 1
2
julia> [0x1] + 1
1-element Array{UInt8,1}:
0x02
julia> 0x0000000000000001 + 1
0x0000000000000002
julia> 0x00000001 + 1
2 where the last one comes out as unsigned instead of signed if you are on a 32 bit Julia. My opinion is that if you have an integer type T other than the default (in the sense of unadorned literals) Int, it is probably for a reason, and you want operations between T and T to stay in T, but likewise for operations between T and Int to stay in T. |
Sorry if this appears elsewhere, but this took me by surprise
results in
where I would have expected Uint8.
In MATLAB, for example, the sum of Uint8's is a Uint8, etc.
What's up? Is this intended, or a quick hack that should be fixed?
The text was updated successfully, but these errors were encountered: