comp.lang.ada
 help / color / mirror / Atom feed
* Math Questions
@ 1999-06-01  0:00 dvdeug
  1999-06-02  0:00 ` Robert Dewar
  1999-06-03  0:00 ` Samuel T. Harris
  0 siblings, 2 replies; 3+ messages in thread
From: dvdeug @ 1999-06-01  0:00 UTC (permalink / raw)
  To: dstarner98

I'm working on a number library for Ada, and I came across some
problems?

(1)Is there any way of dealing with infinity in real numbers in Ada
(like IEEE's +INF)? In my bound float unit, it would be much nicer to
store it as between 1 and infinity than just throw a Constraint Error.

(2)I'd like to create a IEEE745 type, but then you couldn't use it as
the base type for the bound float unit. Is there any way to make a type
look like a number to generics?

(3)Alternately, is there any way to make a generic package accept both
standard floats and any number-like types I create?

--
David Starner - dstarner98@aasaa.ofe.org

--
David Starner - dvdeug@my-dejanews.com, dstarner98@aasaa.ofe.org,
dvdeug@hotmail.com
GURPS: http://w


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Math Questions
  1999-06-01  0:00 Math Questions dvdeug
@ 1999-06-02  0:00 ` Robert Dewar
  1999-06-03  0:00 ` Samuel T. Harris
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Dewar @ 1999-06-02  0:00 UTC (permalink / raw)


In article <7ivc7m$q75$1@nnrp1.deja.com>,
  dstarner98@aasaa.ofe.org wrote:
> (1)Is there any way of dealing with infinity in real numbers
> in Ada (like IEEE's +INF)?

Most ports of GNAT by default provide IEEE infinity semantics.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Math Questions
  1999-06-01  0:00 Math Questions dvdeug
  1999-06-02  0:00 ` Robert Dewar
@ 1999-06-03  0:00 ` Samuel T. Harris
  1 sibling, 0 replies; 3+ messages in thread
From: Samuel T. Harris @ 1999-06-03  0:00 UTC (permalink / raw)


dvdeug@my-deja.com wrote:
> 
> I'm working on a number library for Ada, and I came across some
> problems?
> 
> (1)Is there any way of dealing with infinity in real numbers in Ada
> (like IEEE's +INF)? In my bound float unit, it would be much nicer to
> store it as between 1 and infinity than just throw a Constraint Error.
> 
> (2)I'd like to create a IEEE745 type, but then you couldn't use it as
> the base type for the bound float unit. Is there any way to make a type
> look like a number to generics?

If you custom type is some sort of record, then the answer is no.

> 
> (3)Alternately, is there any way to make a generic package accept both
> standard floats and any number-like types I create?

Yes.

Assuming you have created a custom record type encapsulating
the structure of an IEEE745 type (whatever that is :) then
you will need to define the operations and common attribute
functions.

generic
  type  my_number_type is private;
  with function "+" (left, right : my_number_type) return
my_number_type;
  -- similarly for all the predefined operators.
  with function image (item : my_number_type) return string;
  -- similarly for any attribute-like functions you may need
package whatever is
...
end;

Because you can't force Ada to view your custom record type
as a numeric type. Numeric types are predefined.
However, a generic formal floating point type (fixed point
or integer type for that matter) is a convenient notation
which relieves the programmer from having to include all
the predefined operations in the generic formal part.

You can't take advantage of this notation because
you have created what behave as a numeric, but is NOT
a numeric type. Therefore you are stuck with expanding
the generic formal part to include all the operations
and attribute functions you generic requires.

Such a generic formal part will work for both your
custom type as well as the predefined numeric types,
with the exception of the attribute functions. They
require wrapper functions for the predefined numeric
types.

> 
> --
> David Starner - dstarner98@aasaa.ofe.org
> 
> --
> David Starner - dvdeug@my-dejanews.com, dstarner98@aasaa.ofe.org,
> dvdeug@hotmail.com
> GURPS: http://w
> 
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

-- 
Samuel T. Harris, Principal Engineer
Raytheon, Scientific and Technical Systems
"If you can make it, We can fake it!"




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-06-03  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-01  0:00 Math Questions dvdeug
1999-06-02  0:00 ` Robert Dewar
1999-06-03  0:00 ` Samuel T. Harris

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