Article View: comp.arch
Article #1095Re: arithmetic, was reassociation and undefined behaviour
From: David Brown
Date: Sat, 05 Dec 2026 11:33
Date: Sat, 05 Dec 2026 11:33
23 lines
2595 bytes
2595 bytes
On 04/12/2026 19:10, John Levine wrote: > According to David Brown <david.brown@hesbynett.no>: >> Of course if you want to have a modulo arithmetic system with signed >> integers of a particular size, two's complement wrapping integers are >> great (assuming they match the modulo you want!). But that's not what >> people usually want to model when they use "int" or similar types in >> most languages - they want a type that models mathematical integers as >> well as practically possible with maximally efficient implementations on >> their hardware. > > One's complement and sign-magnitude have symmetrical ranges, but > their implementation is more complicated than two's complement > and they have two versions of zero, +0 and -0 which can also > make code or implementations more complicated. > > Having programed a fair number of two's complement computers over > the past 50 years, I never found the fact that there's an extra > negative number at tne end of the range to be a big problem. The only time it seems to crop up as a problem is people worrying about "abs(INT_MIN)". But to my thinking, that's just another think you don't do because you can't get the right answer.
Technical Details
Message-ID:
<11f0spv$2okjb$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11cpqih$acf5$1@dont-email.me> <TlCQS.44884$7vt4.19168@fx07.iad> <11eus8u$1q9ee$1@dont-email.me> <11euul5$1ritd$1@dont-email.me> <11euvmp$1u6r$2@gal.iecc.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.arch Subject: Re: arithmetic, was reassociation and undefined behaviour Date: Sat, 5 Dec 2026 12:33:19 +0100 Organization: A noiseless patient Spider Lines: 23 Message-ID: <11f0spv$2okjb$1@dont-email.me> References: <11cpqih$acf5$1@dont-email.me> <TlCQS.44884$7vt4.19168@fx07.iad> <11eus8u$1q9ee$1@dont-email.me> <11euul5$1ritd$1@dont-email.me> <11euvmp$1u6r$2@gal.iecc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 05 Dec 2026 11:33:20 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2904683"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yBJBb9Rw8qJdqRfMi1weNFNMeUEMcd3g="; posting-host="e6744434c7b28607c9aa71bc7804445d" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:79/GC5ji8YHX/eD35vfWg+yLFHc= sha256:WqQ2DVLBa+dZHXKwnD9oliDeDHAlZ6gUhszfrxYZmG4= sha1:JtQS+xtW8/7Lo1xMiupCO2u36+s= sha256:PR/IEpvhEmKmuORJo6RzKN2NklNT5aZhrV1cA/RCuYc= Content-Language: en-GB In-Reply-To: <11euvmp$1u6r$2@gal.iecc.com>