🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #1114

Re: reassociation and undefined behaviour

#1114
From: Niklas Holsti
Date: Sat, 05 Dec 2026 21:03
40 lines
3507 bytes
On 2026-12-05 22:34, Stephen Fuld wrote:
> On 12/5/2026 10:40 AM, Michael S wrote:
>> On Sat, 5 Dec 2026 09:53:36 -0800
>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> wrote:
>>
>>> On 12/5/2026 9:33 AM, Michael S wrote:
>>>> On Fri, 4 Dec 2026 13:10:34 -0800
>>>> Stephen Fuld <sfuld@alumni.cmu.edu.invalid> wrote:

    [snip]

>>>>> 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.
>>>
>>> So you want to have a data type that has a range of e.g. 2-7, and
>>> when you add one to seven, you get 2?
>>
>> Yes. The most obvious practical case is -180 to 179.
>> Even more useful for fixed-point (delta) types than for plain integers.
> 
> Wow!  I had missed the point that you said *signed* mod types.  I can 
> see uses for that, but it does seem expensive to implement.

An Ada programmer can define a type (perhaps called Azimuth, eh?) with a 
range from -180 to 179, and overload the arithmetic operations "+", "-", 
"*" to wrap around as desired. Of course that SW implementation is 
slower than HW, but if there is no HW implementation ...

However, I'm sure that the large majority of uses of modular integer 
types in Ada is with power-of-two modulus. This is because their most 
common use is to represent unsigned integers of machine sizes, while 
ordinary (non-modular) integer types in Ada always have a signed base 
type. Thus even a type defined as "range 0 .. 2**32-1" has a signed base 
type of at least 33 bits, which is kind of inconvenient on a 32-bit 
machine. But the type "mod 2**32" is an unsigned 32-bit integer, with 
wrap-around arithmetic.
Technical Details
Message-ID: <nnjcgmF6pt9U1@mid.individual.net>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-nl.newsdeef.eu!srl.newsdeef.eu!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
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> <20261205193318.00007f9f@yahoo.com> <11f1j30$34kqa$1@dont-email.me> <20261205204005.00006fe9@yahoo.com> <11f1sgc$39sup$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-nl.newsdeef.eu!srl.newsdeef.eu!weretis.net!feeder8.news.weretis.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Newsgroups: comp.arch
Subject: Re: reassociation and undefined behaviour
Date: Sat, 5 Dec 2026 23:03:18 +0200
Organization: Tidorum Ltd
Lines: 40
Message-ID: <nnjcgmF6pt9U1@mid.individual.net>
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>
 <20261205193318.00007f9f@yahoo.com> <11f1j30$34kqa$1@dont-email.me>
 <20261205204005.00006fe9@yahoo.com> <11f1sgc$39sup$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net zSruOmpfuxbB7VE2egSGLgT5xjrt7P3RtGb8E/+7YIGVqNxiSw
Cancel-Lock: sha1:cz3d3rPnePgrUd+w18lt3Goia54= sha256:lFURLAGf7idXuASq8W4Vx/d5+kpsCNT51xwmgpBGncM=
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <11f1sgc$39sup$1@dont-email.me>