Re:Using signed or unsigned int by default in C (2015)
by Asooka on Tuesday August 23, 2022 @03:34PM
(#32570220)
The numbers used in computing systems are normal mathematical numbers in the Z_2^32 field. The signed ones are shifted by half the range in the negative direction. There is nothing un-mathematical about them, people who have studied any math in university, i.e. all CS graduates, should have gone through an introductory algebra course that covers fields, rings, etc. So I'm not sure why people keep saying ints are not mathematical.
Re:Using signed or unsigned int by default in C (2015)
by mcguire on Tuesday August 23, 2022 @04:11PM
(#32570805)
To be honest, I adapted a phrase I usually use for floating point numbers.
But anyway, "So making ints signed makes the most sense otherwise there's an impedance mismatch that you need to explain away" is a pretty poor argument when you're dealing with Z_2^32 (or 2^64) minus 2^31, with some operations becoming partial. (And that's assuming you're on a twos-complement machine; those goofy ones-complement boxes had positive and negative zero.)
Re:Using signed or unsigned int by default in C (2015)
by tsimionescu on Tuesday August 23, 2022 @04:05PM
(#32570715)
That depends on the computing system. You're right if we're talking about the processor level (on any modern processor), but the "signed ints" in C or C++ are not a field at all, since INT_MAX + 1 is undefined, as are -INT_MIN and INT_MIN - 1 (and many many many multiplications). Also, as someone else was pointing out, unsigned short arithmetic is not well defined either.
Re:Using signed or unsigned int by default in C (2015)
by qsort on Tuesday August 23, 2022 @04:51PM
(#32571325)
I know what you mean and I'm not saying this with any animus, but this is pretty funny:
> people who have studied any math in university, i.e. all CS graduates, should have gone through an introductory algebra course that covers fields, rings, etc.
> Z_2^32 field
Re:Using signed or unsigned int by default in C (2015)
by jcelerier on Wednesday August 24, 2022 @04:21AM
(#32576359)
> The mathematical definition of "integer" is unbounded above and below.
which is exactly why signed overflow is UB: if you use int, you say "I want something that behaves exactly like a mathematical integer in exchange of the promise of not working with quantities too large"
Re:Using signed or unsigned int by default in C (2015)
by andreareina on Wednesday August 24, 2022 @09:17AM
(#32579063)
That's the first time I've heard that reason for int overflow being UB, do you have a source for that?
Re:Using signed or unsigned int by default in C (2015)
by jcelerier on Thursday August 25, 2022 @03:24AM
(#32590674)
how do you call something that verifies those as axioms? https://gcc.godbolt.org/z/53ben65hf
The "numbers" used in computing systems are not mathematical numbers in any way.