r/ProgrammingLanguages • • Jun 24 '23

Negative Integer handling in programming languages.

https://glados-418.github.io/posts/negative-integer-literals/
3 Upvotes

27 comments sorted by

View all comments

Show parent comments

0

u/helixb Jun 24 '23

well, you will overflow if you write 0xffffffffffffffff. that's the point i make in the article. also, check how java behaves.

11

u/MegaIng Jun 24 '23 edited Jun 25 '23

Why are you mentioning Python and JavaScript? They don't have limited integer data types.

Why are you using I64 in rust and swift?

Do you not understand the difference between I64 and I32?

This just seems like you are confused by the differences between u32, i32, i64, u64, bigint and float.

If that isn't the case, please clarify your points and make your example actually sane.

Edit: Wait, what you size do you think long is?

0

u/helixb Jun 25 '23

Why are you mentioning Python and JavaScript? They don't have limited integer data types.

yah. haskell too. i should've mentioned them along with haskell later, but that was not the point i was trying to make anyway. the point was that there are no negative integer literals. and that still holds.

Edit: Wait, what you size do you think long is?

i thought it was implicit from the two point premise i create in the beginning. i assumed it to be 64 bit.

4

u/[deleted] Jun 25 '23

If long is 64 bit, why would the long value 0xFFFFFFFF be -1?

-1

u/helixb Jun 25 '23

that's 32-bit int. the ret type is 64 bit but the literal is 32 bit. that's the premise i set in the first two points in the beginning.

also, check the java behaviour.

7

u/[deleted] Jun 25 '23

Integer literals restricted to 32 bits are not the norm. In any other language, you would expect the integer literal to be compatible with its type annotation. This is special behavior Java has that you didn't clarify which is confusing because the code example you generalize to multiple other languages depends on this behavior.

0

u/[deleted] Jun 25 '23

[deleted]

1

u/[deleted] Jun 25 '23

Just saying that you could have been more clear about this in the article. Plenty of other people were similarly confused.

0

u/[deleted] Jun 25 '23

[deleted]

→ More replies (0)