Article View: comp.arch
Article #1104Re: reassociation and undefined behaviour
From: Michael S
Date: Sat, 05 Dec 2026 17:33
Date: Sat, 05 Dec 2026 17:33
59 lines
4554 bytes
4554 bytes
On Fri, 4 Dec 2026 13:10:34 -0800 Stephen Fuld <sfuld@alumni.cmu.edu.invalid> wrote: > 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. IIRC, not satisfactory. Programmer is givens no choice w.r.t. lower bound of the modulo range. In that particular regard, they are no better than unsigned types in C. > And lots of > DSPs support saturating arithmetic. > >
Technical Details
Message-ID:
<20261205193318.00007f9f@yahoo.com>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.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> <11eva8b$21n86$1@dont-email.me>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.mb-net.net!open-news-network.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Michael S <already5chosen@yahoo.com> Newsgroups: comp.arch Subject: Re: reassociation and undefined behaviour Date: Sat, 5 Dec 2026 19:33:18 +0200 Organization: A noiseless patient Spider Lines: 59 Message-ID: <20261205193318.00007f9f@yahoo.com> 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> <11eva8b$21n86$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Injection-Date: Sat, 05 Dec 2026 17:33:17 +0000 (UTC) Injection-Info: dont-email.me; logging-data="3186689"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1927lDBwPX9Xl//ukKFAU+vlO08t6MGvZ0="; posting-host="eec2e459ea6ea91de1920b0f3b02bbc3" Cancel-Lock: sha1:aVtpFFQXnYvXn9kckBE7LU4a7wQ= sha256:H418vkPBXNvdceCvec1H2nMoom409+KbocJCtkFmLt8= sha1:HmtFyuvGs3PQczWIWw+dkClB+TM= sha256:k1c2O1IZHdVUg0QH12GzyfW2KVp0fYoas8MzrTRgna0= X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)