Article View: comp.arch
Article #1083Re: reassociation and undefined behaviour
From: Stephen Fuld
Date: Fri, 04 Dec 2026 21:10
Date: Fri, 04 Dec 2026 21:10
49 lines
4204 bytes
4204 bytes
On 12/4/2026 11:29 AM, EricP wrote: > On 2026-Dec-04 13:08, Anton Ertl wrote: >> EricP <ThatWouldBeTelling@thevillage.com> writes: >>> Why is signed twos's complement wrapping mathematically absurd? >> >> It's not. The question is if the programmer wants it. The existence >> of programs that behave with modular arithmetic as intended and don't >> behave as intended with other overflow behaviour shows that there are >> cases where programmers want it. And it has led to compiler >> maintainers adding -fwrapv as a way to telling that property of a >> program to the compiler. >> >>> I'm not a mathy but is it mathematically not just modulo arithmetic >>> with a relabelling of some values? >> >> There is no relabeling, just labeling. With the modulus m, any number >> x is congruent with all numbers x+nm, for any integer n; they form a >> congruence class, which is an equivalence class; i.e., all these >> numbers are equivalent with respect to the modulus m. >> >> You can label the congruence class of all these numbers with any of >> the numbers in the congruence class. One way to label the m >> congruence classes is with 0..m-1. But you can also label them with, >> e.g., (for even m) -m/2..m/2-1. Or in any other way. >> >> - anton > > Yes. But as 0 is a special number, because you can divide any number > by any other number except 0, and as David said it was mathematically > absurd, I was wondering if there was something mathematically different > about wrapping from negative to positive symmetrically around zero > vs asymmetrically from zero to positive. My intuition said there should > be no difference but I'm not a mathy so was asking. > > The reason I ask is because in my hobby language design I have 4 integer > data types, signed and unsigned linear sint and uint with overflow checks, > and signed and unsigned modulo smod and umod. If there is something > wrong with the concept of an "smod" data type I wanted to know. > But it sounds like smod is mathematically ok, though perhaps morally > objectionable to some apple counters of the world. > Later I added signed and unsigned saturating ssat and usat integer types. You might look at Ada as it supports mod data types. And lots of DSPs support saturating arithmetic. -- - Stephen Fuld (e-mail address disguised to prevent spam)
Technical Details
Message-ID:
<11eva8b$21n86$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11cpqih$acf5$1@dont-email.me> <11ejtoe$eoj7$1@dont-email.me> <11el2c1$q43$1@reader2.panix.com> <11emcgn$1k681$1@dont-email.me> <jwvbj74bzm4.fsf-monnier+comp.arch@gnu.org> <11eolqn$2peg5$1@dont-email.me> <2026Dec2.132411@mips.complang.tuwien.ac.at> <11epd07$362ph$1@dont-email.me> <1796263648-5857@newsgrouper.org> <11ergn7$6utu$1@dont-email.me> <2026Dec3.122036@mips.complang.tuwien.ac.at> <1796326998-5857@newsgrouper.org> <11etu0b$1aih9$1@dont-email.me> <TlCQS.44884$7vt4.19168@fx07.iad> <2026Dec4.190839@mips.complang.tuwien.ac.at> <ewEQS.416856$Lt64.284338@fx41.iad>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Stephen Fuld <sfuld@alumni.cmu.edu.invalid> Newsgroups: comp.arch Subject: Re: reassociation and undefined behaviour Date: Fri, 4 Dec 2026 13:10:34 -0800 Organization: A noiseless patient Spider Lines: 49 Message-ID: <11eva8b$21n86$1@dont-email.me> References: <11cpqih$acf5$1@dont-email.me> <11ejtoe$eoj7$1@dont-email.me> <11el2c1$q43$1@reader2.panix.com> <11emcgn$1k681$1@dont-email.me> <jwvbj74bzm4.fsf-monnier+comp.arch@gnu.org> <11eolqn$2peg5$1@dont-email.me> <2026Dec2.132411@mips.complang.tuwien.ac.at> <11epd07$362ph$1@dont-email.me> <1796263648-5857@newsgrouper.org> <11ergn7$6utu$1@dont-email.me> <2026Dec3.122036@mips.complang.tuwien.ac.at> <1796326998-5857@newsgrouper.org> <11etu0b$1aih9$1@dont-email.me> <TlCQS.44884$7vt4.19168@fx07.iad> <2026Dec4.190839@mips.complang.tuwien.ac.at> <ewEQS.416856$Lt64.284338@fx41.iad> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 04 Dec 2026 21:10:35 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2153734"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/76hCYKtRKnDwLK7Q89ibvUrs8UOOGFJw="; posting-host="b21d2a36b8e62635be18f11247693bac" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:mMXyDITaUoRIzHRKGLuTsm8U/k0= sha256:LC55USCbX9t3KElyjJuCUqcZXYRJd5TPcNwZXBJxfHM= sha1:jQM5uTaug563SCxpr42KddOZ9nA= sha256:NI1xMqA80cRY4ErTSA6lgkSTRv9aA/tW3UcEu8KaGts= Content-Language: en-US In-Reply-To: <ewEQS.416856$Lt64.284338@fx41.iad>