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

convert truncates integers #5413

Closed
pygy opened this issue Jan 15, 2014 · 4 comments · Fixed by #8420
Closed

convert truncates integers #5413

pygy opened this issue Jan 15, 2014 · 4 comments · Fixed by #8420
Labels
breaking This change will break code needs decision A decision on this change is needed
Milestone

Comments

@pygy
Copy link
Contributor

pygy commented Jan 15, 2014

d = (Bool=>Int8)[]
d[true] = 2345 # => 2345
d[true] # => 41

The culprit lies here. The key is checked for truncation, but not the value.

@simonster
Copy link
Member

We could check that values are isequal after conversion for Dicts without incurring substantial overhead relative to the cost of hashing, but I'm not sure that really makes sense, since Arrays do the same thing:

julia> d = Array(Int8, 1);

julia> d[1] = 2345
2345

julia> d[1]
41

The underlying reason for this behavior is that convert(Int8, 2345) doesn't throw, even though 2345 can't be expressed as an Int8. This came up previously in #4166 and @StefanKarpinski expressed some misgivings about the present convert behavior, but we decided not to change it then.

@JeffBezanson
Copy link
Member

Yes, this is about convert truncating integers. Given the definition of convert, it is clear that this is incorrect, but it just happens that one very often wants to truncate integers. We should probably bite the bullet and change it.

@JeffBezanson
Copy link
Member

See also #7517. When this is changed, itrunc should be changed too.

@JeffBezanson JeffBezanson added this to the 0.4 milestone Jul 4, 2014
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 needs decision A decision on this change is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants