comp.lang.ada
 help / color / mirror / Atom feed
From: Stuart Redmann <DerTopper@web.de>
Subject: Re: Why use C++?
Date: Fri, 12 Aug 2011 04:48:13 -0700 (PDT)
Date: 2011-08-12T04:48:13-07:00	[thread overview]
Message-ID: <4573053c-23a1-4a23-9afb-fa4d297ff8c5@f41g2000yqh.googlegroups.com> (raw)
In-Reply-To: j203cu$q97$1@dont-email.me

On 10 Aug, Randy Brukardt wrote:
> >> There are uses for wrapping types, but they are far less likely
> >> than wanting overflow detection. The default should be to catch
> >> errors, not turn them into different ones.


Dmitry A. Kazakov wrote
> > The OP mentioned image processing, the behavior frequently needed
> > there is saturated integer arithmetic, which is nether ranged
> > nor modular.
> >
> > As for modular types, wrapping is the mathematically correct
> > behavior, it is not an error.
> >
> >
> > You just cannot provide every possible arithmetic at the language
> > level.


On 11 Aug., "Jed" wrote:
> What do you think the practical level of limitation is? Were you thinking
> "beyond integers" with your statement? What kinds of integer types would
> you like to see built-in to a hypothetical ideal language?


Well, I found the following snippet on
http://www.adaic.org/resources/add_content/standards/05rat/html/Rat-1-3-5.html:

<citation (hopefully covered by fair use ;-)>
Ada 95 introduced modular types which are of course unsigned integers.
However it has in certain cases proved very difficult to get unsigned
integers and signed integers to work together. This is a trivial
matter in fragile languages such as C but in Ada the type model has
proved obstructive. The basic problem is converting a value of a
signed type which happens to be negative to an unsigned type. Thus
suppose we want to add a signed offset to an unsigned address value,
we might have
type Offset_Type is range –(2**31) .. 2**31–1;
type Address_Type is mod 2**32;
Offset: Offset_Type;
Address: Address_Type;
We cannot just add Offset to Address because they are of different
types. If we convert the Offset to the address type then we might get
Constraint_Error and so on. The solution in Ada 2005 is to use a new
functional attribute S'Mod which applies to any modular subtype S and
converts a universal integer value to the modular type using the
corresponding mathematical mod operation. So we can now write
Address := Address + Address_Type'Mod(Offset);
</citation>

This is clearly cumbersome: We have to use a wrapping int for
Address_Type because Ada does not provide a non-signed integer as the
underlying hardware supports (at least not guaranteed by the language
spec).

Ideally, we should be able to do this:
type IncrediblyLargeType is range -1e100 .. +1e100;
and Ada provides some large number representation that is suitable for
this range (Chinese remainder theorem). Why should I worry about
performance? Remember that premature optimization is the root of all
evil. If it takes half a second for multiplication of such types, then
so be it. However, if it turns out that performance matters, I should
be able to add attributes to the type so that Ada can choose a
hardware supported representation.

I think that we could also drop the wrapping ints at all (I consider
them rather a kludge). If someone want wrapping semantics, he could
still write:
type MyType is range 0 .. 100;
MyVar : MyType;
MyVar = (MyVar * MyVar) mod 100;

Be honest, how often do you really _want_ a wrapping int?

Regards,
Stuart



  parent reply	other threads:[~2011-08-12 11:48 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <fb9f787c-af06-427a-82b6-b0684e8dcbc5@s2g2000vby.googlegroups.com>
     [not found] ` <j1kaj8$dge$1@adenine.netfront.net>
     [not found]   ` <1e292299-2cbe-4443-86f3-b19b8af50fff@c29g2000yqd.googlegroups.com>
     [not found]     ` <j1tha5$11q5$1@adenine.netfront.net>
     [not found]       ` <1fd0cc9b-859d-428e-b68a-11e34de84225@gz10g2000vbb.googlegroups.com>
2011-08-10 19:05         ` Why use C++? Niklas Holsti
2011-08-10 22:37           ` Randy Brukardt
2011-08-10 22:49             ` Ludovic Brenta
2011-08-12  4:54               ` Randy Brukardt
2011-08-11  7:54             ` Dmitry A. Kazakov
2011-08-11  8:20               ` Jed
2011-08-11  9:13                 ` Dmitry A. Kazakov
2011-08-11 10:57                   ` Jed
2011-08-11 11:43                     ` Georg Bauhaus
2011-08-12  5:07                       ` Jed
2011-08-11 13:11                     ` Nomen Nescio
2011-08-11 15:11                       ` Paul
2011-08-12  5:15                       ` Jed
2011-08-12 21:39                         ` Fritz Wuehler
2011-08-14  6:52                           ` Jed
2011-08-14  8:13                             ` Nomen Nescio
2011-08-11 15:09                     ` Dmitry A. Kazakov
2011-08-12  5:03                       ` Jed
2011-08-12  8:32                         ` Georg Bauhaus
2011-08-12 13:15                           ` Hyman Rosen
2011-08-12 22:09                             ` Randy Brukardt
2011-08-12 15:14                           ` Jed
2011-08-12 17:20                             ` Georg Bauhaus
2011-08-12 19:51                               ` Jed
2011-08-12 21:22                                 ` Ludovic Brenta
2011-08-14  7:00                                   ` Jed
2011-08-16 13:06                                     ` Ludovic Brenta
2011-08-13  9:37                                 ` Georg Bauhaus
2011-08-14  5:22                                   ` Jed
2011-08-13 10:27                                 ` Georg Bauhaus
2011-08-14  5:35                                   ` Jed
2011-08-14 20:13                                     ` Georg Bauhaus
2011-08-15 11:38                                     ` Georg Bauhaus
2011-08-13 11:02                                 ` Georg Bauhaus
2011-08-14  5:56                                   ` Jed
2011-08-12  9:21                         ` Dmitry A. Kazakov
2011-08-12 13:26                           ` Jed
2011-08-12 14:30                             ` Dmitry A. Kazakov
2011-08-12 19:06                               ` Jed
2011-08-12 20:05                                 ` Dmitry A. Kazakov
2011-08-13  7:53                                   ` Jed
2011-08-13  9:15                                     ` Dmitry A. Kazakov
2011-08-13  9:29                                       ` Ian Collins
2011-08-13  9:52                                         ` Dmitry A. Kazakov
2011-08-13 11:10                                           ` Ian Collins
2011-08-13 11:46                                             ` Georg Bauhaus
2011-08-13 20:30                                               ` Ian Collins
2011-08-13 11:54                                             ` Brian Drummond
2011-08-13 13:12                                               ` Simon Wright
2011-08-14 11:01                                                 ` Brian Drummond
2011-08-14  4:54                                             ` Jed
2011-08-14  4:35                                           ` Jed
2011-08-14  6:46                                             ` Dmitry A. Kazakov
2011-08-14  4:49                                           ` Jed
2011-08-14  6:51                                             ` Dmitry A. Kazakov
2011-08-14  4:29                                       ` Jed
2011-08-14  7:29                                         ` Dmitry A. Kazakov
2011-08-16  8:18                                       ` Nick Keighley
2011-08-16  8:47                                         ` Dmitry A. Kazakov
2011-08-16  9:52                                           ` Nick Keighley
2011-08-16 10:39                                             ` Dmitry A. Kazakov
2011-08-16 10:23                                           ` Georg Bauhaus
2011-08-16 10:58                                             ` Dmitry A. Kazakov
2011-08-16 11:44                                               ` Georg Bauhaus
2011-08-16 14:51                                               ` Bill Findlay
2011-08-16 19:13                                                 ` Dmitry A. Kazakov
2011-08-16 19:23                                                   ` Bill Findlay
2011-08-12 11:48                 ` Stuart Redmann [this message]
2011-08-12 13:12                   ` Vinzent Hoefler
2011-08-12 15:50                     ` Stuart Redmann
2011-08-12 17:02                       ` Bill Findlay
2011-08-15 12:59                       ` Vinzent Hoefler
2011-08-12  5:02               ` Randy Brukardt
2011-08-12  5:16                 ` Robert Wessel
2011-08-12 16:39                   ` Adam Beneschan
2011-08-12  5:24                 ` Jed
2011-08-12  6:51                   ` Paavo Helde
2011-08-12  7:41                     ` Georg Bauhaus
2011-08-12 15:50                   ` Fritz Wuehler
2011-08-12 19:59                     ` Jed
2011-08-13  8:06                     ` Stephen Leake
2011-08-12  9:40                 ` Dmitry A. Kazakov
2011-08-12  9:45                   ` Ludovic Brenta
2011-08-12 10:48                     ` Georg Bauhaus
2011-08-12 15:56                       ` Ludovic Brenta
2011-08-13  8:08                   ` Stephen Leake
2011-08-18 13:39               ` Louisa
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox