comp.lang.ada
 help / color / mirror / Atom feed
From: mgk25@cl.cam.ac.uk (Markus Kuhn)
Subject: Re: Ada and Java. different behaviour. casting long to int problem.
Date: 1999/06/17
Date: 1999-06-17T00:00:00+00:00	[thread overview]
Message-ID: <7kb9ep$hej$1@pegasus.csx.cam.ac.uk> (raw)
In-Reply-To: f92d7yyweva.fsf@eng.sun.com

Mark Hood <hood@eng.sun.com> writes:
|> > In Java, nothing happens, and life goes on and the final number is wrong,
|> > but no one really knows it is wrong, or may be someone will notice it is
|> > wrong.
|> 
|> I think the point is that the result of an overflow isn't necessarily the
|> wrong number.  
|> 
|> For example, one could be working with data that needs to be expressed in
|> some signed 16-bit quantized space, and wish to encode consecutive elements
|> in that space as deltas from previous values in a streamed fashion.  In that
|> case the overflow semantics are essential, since otherwise it wouldn't be
|> possible to express the delta between -30000 and +30000 in 16 bits.
|> 
|> The example isn't contrived; it's common in compression algorithms.  My
|> impression is that Ada is oriented toward numerical applications, and so the
|> overflow checks are probably appropriate.  It would certainly be
|> inconvenient for many Java applications if the defined behavior of signed
|> 2's complement integers were thwarted.

Just for the record: Ada95 does have so-called "modular integer
types" such as Unsigned_8, Unsigned_64, etc.  These do overflow
without raising any exception, for exactly the applications that
you mentioned, just like the corresponding unsigned int types
in C.

If X is a modular type, then you always get X'Last + 1 = 0 in
Ada95. (X'Last is just the Ada notation for the highest possible
value that variable X can possibly have, e.g. 255 for X : Unsigned_8).

Modular integer types were one of the many important improvements
that were made to Ada in the 1995 complete revision of the language,
and they are invaluable for high-performance coding of many signal
processing algorithms.

Your impression that Ada is "oriented toward numerical applications"
is not true any more for the modern Ada95 language that the GNAT compiler
implements. Ada95 is in my experience at least as well suited for
high-performance bit fiddling in data compression, data encryption,
and signal processing algorithms as C is. But in addition to C,
you get the safety and comfort features of Java as well.

For me, Ada95 combines the best of both the C and the Java world:
High performance, low-level access as well as type safety, and comfort.
It is amazing how underhyped this equally young language is
compared to Java in the trade press. But then, who asks the trade
press ...

Markus

-- 
Markus G. Kuhn, Computer Laboratory, University of Cambridge, UK
Email: mkuhn at acm.org,  WWW: <http://www.cl.cam.ac.uk/~mgk25/>




  parent reply	other threads:[~1999-06-17  0:00 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-06-12  0:00 Ada and Java. different behaviour. casting long to int problem nabbasi
1999-06-12  0:00 ` Tucker Taft
1999-06-12  0:00   ` Keith Thompson
1999-06-12  0:00     ` kirck
1999-06-13  0:00       ` Robert Dewar
1999-06-12  0:00         ` Fred
1999-06-14  0:00           ` Mark Hood
1999-06-15  0:00             ` mike
1999-06-15  0:00               ` Marin David Condic
1999-06-15  0:00                 ` Mike Silva
1999-06-15  0:00                   ` rich
1999-06-15  0:00                     ` Samuel Mize
1999-06-15  0:00                     ` tmoran
1999-06-15  0:00                       ` David Botton
1999-06-16  0:00                       ` Richard D Riehle
1999-06-16  0:00                       ` Samuel Mize
1999-06-15  0:00                     ` Marin David Condic
1999-06-15  0:00                       ` D'Arcy Smith
1999-06-15  0:00                         ` Keith Thompson
1999-06-16  0:00                           ` D'Arcy Smith
1999-06-16  0:00                           ` bill
1999-06-16  0:00                             ` George W. Bayles
1999-06-16  0:00                               ` Fraser Wilson
1999-06-17  0:00                               ` Chris Dollin
1999-06-17  0:00                               ` Aidan Skinner
1999-06-17  0:00                                 ` David Botton
1999-06-18  0:00                                   ` Dale Stanbrough
1999-06-18  0:00                                     ` Matthew Heaney
1999-06-18  0:00                                     ` David Botton
1999-06-18  0:00                                       ` Pascal Obry
1999-07-20  0:00                             ` Geoff Bull
1999-06-16  0:00                         ` George W. Bayles
1999-06-16  0:00                           ` D'Arcy Smith
1999-06-16  0:00                           ` Tucker Taft
1999-06-17  0:00                             ` George W. Bayles
1999-06-17  0:00                               ` Tucker Taft
1999-06-17  0:00                                 ` bob
1999-06-16  0:00                           ` D'Arcy Smith
1999-06-17  0:00                           ` Larry Kilgallen
1999-06-16  0:00                         ` Mike Silva
1999-06-16  0:00                           ` D'Arcy Smith
1999-06-16  0:00                             ` kirk
1999-06-16  0:00                               ` D'Arcy Smith
1999-06-17  0:00                                 ` Markus Kuhn
1999-06-17  0:00                                   ` john
1999-06-17  0:00                                     ` Ed Falis
1999-06-18  0:00                                     ` Aidan Skinner
1999-06-17  0:00                                   ` D'Arcy Smith
1999-06-16  0:00                               ` Hyman Rosen
1999-06-17  0:00                                 ` Jean-Pierre Rosen
1999-06-17  0:00                                   ` Marin David Condic
1999-06-17  0:00                                     ` Samuel Mize
1999-06-17  0:00                                       ` Marin David Condic
1999-06-22  0:00                                         ` Hyman Rosen
1999-06-22  0:00                                           ` Keith Thompson
1999-06-23  0:00                                             ` Marin David Condic
1999-06-24  0:00                                               ` Robert A Duff
1999-06-24  0:00                                                 ` Marin David Condic
1999-06-23  0:00                                           ` Marin David Condic
1999-06-18  0:00                                       ` Aidan Skinner
1999-06-17  0:00                                 ` Markus Kuhn
1999-06-17  0:00                                 ` Robert I. Eachus
1999-06-17  0:00                                   ` Hyman Rosen
1999-06-17  0:00                                     ` bob
1999-06-18  0:00                                       ` Hyman Rosen
1999-06-18  0:00                                         ` mike
1999-06-18  0:00                                           ` Hyman Rosen
1999-06-19  0:00                                             ` Dale Stanbrough
1999-06-21  0:00                                               ` Marin David Condic
1999-06-19  0:00                                             ` Samuel Mize
1999-06-21  0:00                                               ` Marin David Condic
1999-06-21  0:00                                             ` Mike Silva
1999-06-17  0:00                                     ` Marin David Condic
1999-06-20  0:00                                 ` Sera Hirasuna
1999-06-19  0:00                                   ` Kio
1999-06-20  0:00                                   ` Vladimir Olensky
1999-06-21  0:00                                   ` Hyman Rosen
1999-06-21  0:00                                   ` Samuel T. Harris
1999-06-22  0:00                                     ` Richard D Riehle
1999-06-22  0:00                                     ` Robert I. Eachus
1999-06-23  0:00                                       ` Aidan Skinner
1999-06-23  0:00                                       ` Richard D Riehle
1999-06-17  0:00                           ` Jean-Pierre Rosen
1999-06-16  0:00                         ` Marin David Condic
1999-06-22  0:00                       ` Robert Dewar
1999-06-23  0:00                         ` Marin David Condic
1999-06-23  0:00                           ` Vladimir Olensky
1999-06-23  0:00                             ` Marin David Condic
1999-06-23  0:00                             ` Roedy Green
1999-06-23  0:00                               ` Marin David Condic
1999-06-23  0:00                                 ` Keith Thompson
1999-06-24  0:00                                   ` Mike Silva
1999-06-24  0:00                                   ` Marin David Condic
1999-06-16  0:00                 ` Mark Hood
1999-06-17  0:00                   ` Jean-Pierre Rosen
1999-06-17  0:00                 ` Robert I. Eachus
1999-06-17  0:00                   ` Marin David Condic
1999-06-15  0:00               ` D'Arcy Smith
1999-06-16  0:00                 ` George W. Bayles
1999-06-16  0:00                   ` D'Arcy Smith
1999-06-17  0:00                   ` Aidan Skinner
1999-06-17  0:00                   ` Matthew Heaney
1999-06-15  0:00               ` Samuel Mize
1999-06-15  0:00                 ` jerry
1999-06-16  0:00                   ` Richard D Riehle
1999-06-16  0:00                     ` jerry
1999-06-17  0:00             ` Markus Kuhn [this message]
1999-06-17  0:00               ` David Botton
1999-06-12  0:00   ` PPAATT
1999-06-13  0:00   ` Robert Dewar
1999-06-14  0:00     ` tmoran
1999-06-30  0:00       ` John Merryweather Cooper
1999-07-01  0:00         ` Chad R. Meiners
1999-07-02  0:00           ` Robert Dewar
1999-07-02  0:00             ` John Merryweather Cooper
1999-07-03  0:00               ` Robert Dewar
1999-06-12  0:00 ` nabbasi
1999-06-12  0:00   ` jerry
1999-06-12  0:00     ` Robert Dewar
1999-06-14  0:00       ` Marin David Condic
replies disabled

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