comp.lang.ada
 help / color / mirror / Atom feed
From: "Steven Deller" <deller@smsail.com>
To: <comp.lang.ada@ada.eu.org>
Subject: Math Update for Ada 2005
Date: Sat, 22 Dec 2001 11:56:46 -0500
Date: 2001-12-22T11:56:46-05:00	[thread overview]
Message-ID: <mailman.1009040342.32000.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <9vvtrf$iqq$1@nh.pace.co.uk>

All the email about Math libraries reminded me of one of Ada 95's
shortcomings.

The IEEE math definitions have included NaN and Inf semantics for quite
some time. Many (if not all) native platforms and many embedded
platforms can support this.  I have run into C++ and C code that uses
these.  Ada 95 does NOT support these.

Interfacing Ada with C or C++ code that uses these can be quite a pain.

How could we add these semantics into Ada 2005 without breaking past
code and without *forcing* platforms to support this (if they don't do
so easily).

My thought was to have some sort of program wide values for floating
point (settable?), with appropriate attributes to query the settings.

Is that reasonable?

Does anyone else want these semantics available?

Suppose you have a subtype with narrow constraints (less than the 'Base
range).  Would Inf and NaN apply?  I believe it would.

I'd suggest that wherever raising constraint_error (for these types)
would occur, instead the values would be set directly to "Inf" or "NaN"
(consistent with IEEE semantics).  Basically, if 'Base includes Inf and
NaN values, then any subtype would include them as well.   Or more to
the point, any and all floating point types either would, or would not,
include the values Inf and NaN (and appropriate semantics).

Addition of these values would not require any additional constraint
checking beyond that which is done now.  Wherever code (without NaN and
Inf) would have done a constraint check:
  if val<low_bound then raise constraint_error
  if val>hi_bound then raise constraint_error

code (with NaN and Inf) would now be generated as
  if val /= NaN and val<low_bound then val := -Inf
  if val /= NaN and val>hi_bound then val := +Inf

I seem to recall (?) that the "two" predicates are really just one test
in IEEE arithmetic, i.e. I believe there is a way to check for something
being "commensurate" and then comparing values, so the resulting code
should not be any more complex or costly than current code. 

Typical application code could then look like:
  do lots of computations to compute one or more values
  if val = Inf then
    do things based on value going out of range
    including possibly explicitly raising constraint_error
  end if

  if val = NaN then
    ...

The state could even be settable (perhaps at execution startup).  In
that case, there would have to be a test for the state (to decide
whether to raise constraint_error or set a value to +/-Inf) though there
might be some clever load time operations that could eliminate that
test.

This model can simplify code in many situations.  When it is EXPECTED
that something may go out of range and "that is ok", then raising an
exception is not necessarily the right thing to do, particularly if the
computation code "consumes" some inputs.  The current Ada model *forces*
an application to either "consume all data before computing", wrap an
exception handler around every data "consumption", or have coupling
between code and one "overall" exception handler so the handler knows
how much data to "skip".   None of these may be as satisfactory as:
  loop
   get data
   compute some
   get more data
   compute some
   get more data
   compute some
   if NaN or Inf values then
     output something
   else
     output something else
   end if 
  end loop

Regards,
Steven Deller




  parent reply	other threads:[~2001-12-22 16:56 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-11  9:33 Ada2005 Peter Hermann
2001-12-11 11:05 ` Ada2005 M. A. Alves
2001-12-11 11:55   ` Ada2005 Aaro Koskinen
2001-12-11 14:49     ` Ada2005 Wes Groleau
2001-12-11 14:58     ` Ada2005 Marin David Condic
2001-12-11 15:18       ` Ada2005 Ted Dennison
2001-12-12  8:37       ` Ada2005 Alfred Hilscher
2001-12-11 11:23 ` Ada2005 Martin Dowie
2001-12-11 11:54 ` Ada2005 Preben Randhol
2001-12-11 12:06 ` Ada2005 Larry Kilgallen
2001-12-11 14:39 ` Ada2005 Ted Dennison
2001-12-12  4:39   ` Ada2005 Jeffrey Carter
2001-12-13 18:39   ` Ada2005 Randy Brukardt
2001-12-12 11:29 ` Ada2005 Peter Hermann
2001-12-12 12:42   ` Ada2005 Larry Kilgallen
2001-12-12 12:51   ` Ada2005 Martin Dowie
2001-12-12 12:59   ` Ada2005 Carsten Freining
2001-12-12 14:40     ` Ada2005 Peter Hermann
2001-12-12 15:16       ` Ada2005 Ted Dennison
2001-12-12 15:37         ` Ada2005 Larry Kilgallen
2001-12-12 17:49           ` Ada2005 Ted Dennison
2001-12-12 18:02         ` Ada2005 tmoran
2001-12-12 18:17           ` Ada2005 Ted Dennison
2001-12-12 18:31             ` Ada2005 Sergey Koshcheyev
2001-12-12 19:08               ` Ada2005 Ted Dennison
2001-12-12 18:14         ` Ada2005 Mark Lundquist
2001-12-12 18:40           ` Ada2005 Ted Dennison
2001-12-12 19:12             ` Ada2005 Mark Lundquist
2001-12-12 19:41               ` Ada2005 Ted Dennison
2001-12-13 20:07         ` Ada2005 Ted Dennison
2001-12-14  4:40       ` Ada2005 Patrick Hohmeyer
2001-12-14  9:55         ` Ada2005 Lutz Donnerhacke
2001-12-14 10:36         ` Ada2005 Dmitry A. Kazakov
2001-12-17 18:40         ` Ada2005 Matthew Heaney
2001-12-12 18:04     ` Ada2005 Mark Lundquist
2001-12-12 21:25       ` Ada2005 Mark Lundquist
2001-12-13 18:40         ` Ada2005 Stephen Leake
2001-12-13 19:01           ` Ada2005 Mark Lundquist
2001-12-14 17:17             ` Ada2005 Stephen Leake
2001-12-13  9:11       ` Ada2005 Dmitry A. Kazakov
2001-12-17 17:50         ` Ada2005 Ray Blaak
2001-12-18 11:55           ` Ada2005 Dmitry A. Kazakov
2001-12-18 19:51             ` Ada2005 Ray Blaak
2001-12-19  8:34               ` Ada2005 Dmitry A. Kazakov
2001-12-19 13:30                 ` Ada2005 Mark Lundquist
2001-12-19 18:23                 ` Ada2005 Ray Blaak
2001-12-19 18:20           ` Ada2005 Mark Lundquist
2001-12-19 19:19             ` Ada2005 Ray Blaak
2001-12-20 14:17             ` Ada2005 Dmitry A. Kazakov
2001-12-20 11:24       ` Ada2005 Carsten Freining
2001-12-20 14:27         ` Ada2005 Mark Lundquist
2001-12-20 15:01         ` Ada2005 Matthew Woodcraft
2001-12-20 15:45         ` Ada2005 Mark Lundquist
2001-12-20 16:20           ` Ada2005 Mark Lundquist
2001-12-13 18:13     ` Ada2005 Georg Bauhaus
2001-12-20 16:34 ` Math Libraries (was Re: Ada2005) Marin David Condic
2001-12-20 20:14   ` FGD
2001-12-20 20:34     ` Marin David Condic
2001-12-21 17:21       ` FGD
2001-12-21 18:08         ` Marin David Condic
2001-12-21 19:40           ` tmoran
2001-12-21 19:45             ` Marin David Condic
2001-12-21 20:35             ` Dan Nagle
2001-12-21 20:31           ` Eric Merritt
2001-12-22 16:56           ` Steven Deller [this message]
2001-12-23 15:13             ` Math Update for Ada 2005 Robert Dewar
2001-12-23 22:43               ` Brian Rogoff
2001-12-22 21:48           ` Math Libraries (was Re: Ada2005) FGD
2002-01-02 14:20         ` Jacob Sparre Andersen
2001-12-20 23:20   ` Robert C. Leif, Ph.D.
2001-12-21 14:49     ` 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