Hello! I was just wondering if anybody knew the space (bytes) numbers (integers, unsigned integers, floats, everything) take in Rust?

sorry if this is a stupid question, I am new to Rust and low-level programming in general

Hello! I was just wondering if anybody knew the space (bytes) numbers (integers, unsigned integers, floats, everything) take in Rust?

sorry if this is a stupid question, I am new to Rust and low-level programming in general

Thank you!

Also, if unsigned integers take up the same amount of memory as signed integers, why do unsigned integers exist in the first place? Wouldn't everyone only use signed integers?

Signed integers use up half of their range on negative numbers, which are unnecessary for many use cases. (For example, a vector's length can't be negative.)

This means that u8 can count up to 255, while i8 can only go up to 127.

And for use cases where negative numbers don't make sense, it's actually useful to know that you will never get a negative number.

1 Like

Thanks!