Skip to content
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 changes in scalar computation #3759

Closed
lindahua opened this issue Jul 19, 2013 · 4 comments · Fixed by #8420
Closed

Type changes in scalar computation #3759

lindahua opened this issue Jul 19, 2013 · 4 comments · Fixed by #8420
Labels
breaking This change will break code
Milestone

Comments

@lindahua
Copy link
Contributor

On latest commit, I find:

julia> typeof(-int32(1))
Int64

julia> typeof(ones(Int32,1))
Array{Int32,1}

Actually, any arithmetic operation on Int32 scalars yields Int64 scalar, and operations on Int32 arrays yields Int32 array.

Is this supposed the case? or a bug?

@StefanKarpinski
Copy link
Member

This is actually intentional. The idea is that arithmetic always promotes to the system int size since that preserves values and you might as well. For arrays, on the other hand, you don't want to blow your result up if you're working with, e.g. Int16s, then you want the result to still be an Int16 array. Intermediate computations are done with Ints though.

@lindahua
Copy link
Contributor Author

Thanks for the explanation. This makes sense.

@timholy
Copy link
Member

timholy commented Aug 16, 2014

Anyone who really wants to break a bunch of packages should tackle this!

I wonder if we can generalize our promotion system at the same time, see #8027.

JeffBezanson added a commit that referenced this issue Sep 17, 2014
…> T (#3759)

the sysimg builds, but still need to:
  - check same-size signed<->unsigned conversion
  - make tests pass
@JeffBezanson
Copy link
Member

closed by #8420

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code
Projects
None yet
4 participants