Skip to content

uint accepts negative numbers #184

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

Closed
nth10sd opened this issue Nov 21, 2010 · 1 comment
Closed

uint accepts negative numbers #184

nth10sd opened this issue Nov 21, 2010 · 1 comment

Comments

@nth10sd
Copy link

nth10sd commented Nov 21, 2010

fn main() {
    let uint x = -1 as uint;
    log x;
}

This testcase seems to show that negative numbers can be accepted as unsigned integers. Unsigned integers should only comprise of non-negative numbers.

(not sure if this is working as intended.)

On repository revision 5955e23 on Mac 10.6.5.

Output:
$ ./rustboot -L . -o 2out.out 2test.rs

$ ./2out.out

rt: ---
rt: a5ed:main:main: rust: -1 (0xffffffff)

@graydon
Copy link
Contributor

graydon commented Nov 21, 2010

This is correct behavior. The "as" operator performs a cast. "-1" is an int, and "as uint" casts it to uint. The logging system that displays "-1" and "0xffffffff" simply doesn't know enough to differentiate int and uint, so it displays both. Limitation of the logging system.

kazcw pushed a commit to kazcw/rust that referenced this issue Oct 23, 2018
* Add _mm_unpackhi_pd and _mm_unpacklo_pd
dlrobertson pushed a commit to dlrobertson/rust that referenced this issue Nov 29, 2018
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
@rustbot rustbot mentioned this issue Nov 4, 2024
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants