comp.lang.ada
 help / color / mirror / Atom feed
* Using complex from interfaces.fortran.
@ 1995-02-22 22:40 Brian Hanson
  1995-02-28 22:21 ` Tucker Taft
  0 siblings, 1 reply; 2+ messages in thread
From: Brian Hanson @ 1995-02-22 22:40 UTC (permalink / raw)


I was looking at the package Interfaces.Fortran.  Suppose you want to work
with complex numbers.  There is a type defined in this package called Complex
and you can do all the normal stuff with it but suppose you wish to output a
complex number.  How to do it?

with Interfaces.Fortran; use Interfaces.fortran;
with ada.text_io.complex_io;
procedure test is
  package complex_io is new ada.text_io.complex_io
	(single_precision_complex_types);
  with complex_io;

  a, b, c: complex;

begin
  a := (1.7, 2.8);
  b := (9.5, 6.2);

  c := a * b + complex'(2.3, 0.0);
  put(c);
end;

My expectation is that the put not compile because it expects the type
single_precision_complex_types.complex and not the complex defined in 
fortran.

Is this true.  If so, does it not make using complex from package fortran
very awkward for io and functions like sin, cos which are also accessed
via a generic package with a package parameter?


-- Brian Hanson
-- brh@cray.com

ps. I attempted to try this with gnat 2.03 but got compile errors for
the package instantiation.  So I do not know if it is gnat that is wrong
or my program that is wrong.


-- 
----
-- Brian Hanson
-- brh@cray.com



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

* Re: Using complex from interfaces.fortran.
  1995-02-22 22:40 Using complex from interfaces.fortran Brian Hanson
@ 1995-02-28 22:21 ` Tucker Taft
  0 siblings, 0 replies; 2+ messages in thread
From: Tucker Taft @ 1995-02-28 22:21 UTC (permalink / raw)


Brian Hanson (brh@cray.com) wrote:

: I was looking at the package Interfaces.Fortran.  Suppose you want to work
: with complex numbers.  There is a type defined in this package called Complex
: and you can do all the normal stuff with it but suppose you wish to output a
: complex number.  How to do it?

: with Interfaces.Fortran; use Interfaces.fortran;
: with ada.text_io.complex_io;
: procedure test is
:   package complex_io is new ada.text_io.complex_io
: 	(single_precision_complex_types);
:   with complex_io;
    ^^^^ "use" presumably

:   a, b, c: complex;

: begin
:   a := (1.7, 2.8);
:   b := (9.5, 6.2);

:   c := a * b + complex'(2.3, 0.0);
:   put(c);
: end;

: My expectation is that the put not compile because it expects the type
: single_precision_complex_types.complex and not the complex defined in 
: fortran.

: Is this true.  

Yes, that is your problem.

: ... If so, does it not make using complex from package fortran
: very awkward for io and functions like sin, cos which are also accessed
: via a generic package with a package parameter?

Yes, this seems like an unintended consequence of making
Interfaces.Fortran.Complex a derived type.  A subtype would
probably have been better, though that would require the
user to do a "use type Interfaces.Fortran.Complex" rather
than a "use Interfaces.Fortran" to get direct visibility
to the operators (not so terrible IMHO).  Oh well, you can't
win them all.

In any case, you can work around the problem in two ways.
One, insert an explicit conversion in the call on "Put", e.g.:

   Put(Single_Precision_Complex_Types.Complex(C));

or two, avoid use of Interfaces.Fortran.Complex and instead
use Interfaces.Fortran.Single_Precision_Complex_Types.Complex
directly.  In the latter case, you might want to locally
declare "Complex" to be a subtype of 
Single_Precision_Complex_Types.Complex and then do a
"use type Complex;"

: -- Brian Hanson
: -- brh@cray.com

: ps. I attempted to try this with gnat 2.03 but got compile errors for
: the package instantiation.  So I do not know if it is gnat that is wrong
: or my program that is wrong.

The instantiation looks OK.  GNAT might not fully support
formal package parameters yet; send a report to gnat-report
to find out for sure.

-Tucker Taft   stt@inmet.com



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

end of thread, other threads:[~1995-02-28 22:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-02-22 22:40 Using complex from interfaces.fortran Brian Hanson
1995-02-28 22:21 ` Tucker Taft

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