comp.lang.ada
 help / color / mirror / Atom feed
From: Mario Amado Alves <maa@di.fct.unl.pt>
To: "comp.lang.ada@list.deja.com" <comp.lang.ada@list.deja.com>
Subject: Numeric types
Date: 1999/12/08
Date: 1999-12-08T00:00:00+00:00	[thread overview]
Message-ID: <Pine.LNX.4.10.9912081930170.2845-100000@lexis.di.fct.unl.pt> (raw)
In-Reply-To: 8233fm$ngf$1@nntp3.atl.mindspring.net

The manual defines "numeric types" as the set of integer and real types
(cf. e.g. 3.5).

Now, is it a codeable type, viz. is it possible to have a generic formal
parameter of numeric type, meaning inheriting all numeric operations ("+", 
"*", ...)? E.g.:

  generic
    type Numeric_Type is ...; -- what here?
  package Blob is
    -- ...
  end Blob;

  package body Blob is
    -- code using numeric operations ("+", "*", etc.), e.g.:
    function Blib(A, B, C: Numeric_Type) return Numeric_Type is
    begin
      return(A + B * C);      
    end Blib;
  end Blob;

Is this possible to code properly? And how would we write "zero" in this
idiom (or any other literal for that matter)? It must be a commonality of
"0" and "0.0". This would perhaps work:

  function Zero return Numeric_Type is
  begin
    return(Numeric_Type'Value("0"));
  exception
    when others =>
      return(Numeric_Type'Value("0.0"));
  end Zero;

but it sounds like a dirty trick. An attribute 'Zero would be nice...

But I am afraid the idiom is just not possible. Please confirm. Perhaps
with class wide programming... I will have to go through Chapter 12 of
Cohen's bookin once more; perhaps I will be able to answer my onw questions
before the end of the year. But from the class hierachy of the types
involved, viz:

    scalar
       discrete
          integer
          ...
       real
       ...

I think it cannot be done. A numeric class should have the interset
fo integer and real operations but leaving out some discrete operations
like 'Pos and 'Val. The manual itself warns:

"The classes ``numeric'' and ``nonlimited'' represent other classification 
dimensions and do not fit into the above strictly hierarchical picture. "
(3.2)

But what "classes" are exactly refered to here? Numeric_IO?

Thanks in advance for any suggestions.

| |,| | | |RuaFranciscoTaborda24RcD 2815-249CharnecaCaparica 351+212976751
|M|A|R|I|O|                                                  mob 939354005
|A|M|A|D|O|DepartmentoDeInformaticaFCT/UNL 2825-114 Caparica 351+212958536
|A|L|V|E|S|                                                  fax 212948541
| | | | | |                 maa@di.fct.unl.pt                FCT 212948300



 Sent via Deja.com http://www.deja.com/
 Before you buy.




  parent reply	other threads:[~1999-12-08  0:00 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-28  0:00 Decoding an octet stream Florian Weimer
1999-11-29  0:00 ` David C. Hoos, Sr.
1999-11-30  0:00   ` Florian Weimer
1999-12-03  0:00     ` Robert Dewar
1999-12-01  0:00   ` Robert Dewar
1999-12-01  0:00     ` Geoff Bull
1999-12-01  0:00       ` Robert Dewar
1999-12-01  0:00     ` David C. Hoos, Sr.
1999-12-01  0:00       ` Robert Dewar
1999-12-07  0:00         ` Stefan Skoglund
1999-12-01  0:00       ` swhalen
1999-12-01  0:00         ` Florian Weimer
1999-12-02  0:00           ` Ted Dennison
1999-12-02  0:00             ` tmoran
1999-12-02  0:00           ` Robert Dewar
1999-12-02  0:00           ` Geoff Bull
1999-12-02  0:00             ` Lutz Donnerhacke
1999-12-01  0:00         ` Larry Kilgallen
1999-12-01  0:00           ` Kenneth Almquist
1999-12-02  0:00             ` Geoff Bull
1999-12-02  0:00               ` Stupid patent tricks (was: Decoding an octet stream) Ted Dennison
1999-12-06  0:00               ` Decoding an octet stream Kenneth Almquist
1999-12-02  0:00         ` Geoff Bull
1999-12-02  0:00           ` Robert Dewar
1999-12-02  0:00           ` swhalen
1999-12-02  0:00             ` Larry Kilgallen
1999-12-03  0:00               ` Geoff Bull
1999-12-03  0:00               ` swhalen
1999-12-04  0:00                 ` Geoff Bull
1999-12-06  0:00                   ` Robert Dewar
1999-12-04  0:00                 ` Robert Dewar
1999-12-06  0:00               ` Richard D Riehle
1999-12-06  0:00                 ` Ed Falis
1999-12-07  0:00                   ` Ted Dennison
1999-12-08  0:00                 ` Robert Dewar
1999-12-08  0:00                   ` Brian Rogoff
1999-12-08  0:00         ` Mario Amado Alves [this message]
1999-12-08  0:00           ` Numeric types Tucker Taft
1999-12-01  0:00       ` Decoding an octet stream Robert Dewar
replies disabled

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