Article View: comp.arch
Article #1080Re: reassociation and undefined behaviour
From: EricP
Date: Fri, 04 Dec 2026 19:29
Date: Fri, 04 Dec 2026 19:29
42 lines
3588 bytes
3588 bytes
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.
Technical Details
Message-ID:
<ewEQS.416856$Lt64.284338@fx41.iad>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!news.quux.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer05.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.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>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!weretis.net!feeder9.news.weretis.net!news.quux.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer05.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx41.iad.POSTED!not-for-mail MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: reassociation and undefined behaviour Newsgroups: comp.arch 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> Content-Language: en-CA From: EricP <ThatWouldBeTelling@thevillage.com> In-Reply-To: <2026Dec4.190839@mips.complang.tuwien.ac.at> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Lines: 42 Message-ID: <ewEQS.416856$Lt64.284338@fx41.iad> X-Complaints-To: abuse@UsenetServer.com NNTP-Posting-Date: Fri, 04 Dec 2026 19:29:14 UTC Date: Fri, 4 Dec 2026 14:29:11 -0500 X-Received-Bytes: 3274