comp.lang.ada
 help / color / mirror / Atom feed
* Re: Putting a 'Duration' on the screen ?
  1999-01-18  0:00 Putting a 'Duration' on the screen ? Emmanuel Lambert
  1999-01-18  0:00 ` Marin David Condic
@ 1999-01-18  0:00 ` Steve O'Neill
  1999-01-19  0:00   ` Matthew Heaney
  1999-01-18  0:00 ` Tom Moran
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Steve O'Neill @ 1999-01-18  0:00 UTC (permalink / raw)


Emmanuel Lambert wrote:

> I am freaking out because I would like to output a variable from type
> Duration to the screen, but it does not work with put(...). I have
> included Ada.Float_Text_Io, but that does not help. Can someone give me
> a hint.

The hint is - Duration is not a floating point type, it's a fixed point
type.  Either instantiate Fixed_IO for Duration or convert the duration
object to float.





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

* Re: Putting a 'Duration' on the screen ?
  1999-01-18  0:00 Putting a 'Duration' on the screen ? Emmanuel Lambert
@ 1999-01-18  0:00 ` Marin David Condic
  1999-01-18  0:00   ` David C. Hoos, Sr.
  1999-01-18  0:00 ` Steve O'Neill
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Marin David Condic @ 1999-01-18  0:00 UTC (permalink / raw)
  To: Emmanuel Lambert

Ada.Float_Text_IO doesn't work because Duration is not a floating point
type. It is a fixed point type. You've got two choices here:

with Ada.Text_IO.Fixed_IO ;
procedure Blah_Blah_Blah is
    package
        My_Fixed_IO
    is new
        Ada.Text_IO.Fixed_IO (
            Num => Duration) ;
    --  After this, you have a procedure My_Fixed_IO.Put you can call...
...
...
...
*OR*

Ada.Text_IO.Put_Line ("Current Duration: " & Duration'Image (X)) ;

where X above is declared to be of type Duration. The numeric types have
the 'Image attribute which will return a string. See the ARM 3.5 (35)
for a definition.

Hope this helps.

MDC


Emmanuel Lambert wrote:
> 
> Hi,
> 
> I am freaking out because I would like to output a variable from type
> Duration to the screen, but it does not work with put(...). I have
> included Ada.Float_Text_Io, but that does not help. Can someone give me
> a hint. I a unable to find good documentation on this.
> 
> Thanks
> Emmanuel Lambert

-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
Ph: 561.796.8997         Fx: 561.796.4669
***To reply, remove "bogon" from the domain name.***

    "Nobody shot me."

        --  Last words of Frank Gusenberg when asked by police who
            shot him fourteen times with a machine gun in the Saint
            Valentine's Day Massacre.




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

* Re: Putting a 'Duration' on the screen ?
  1999-01-18  0:00 Putting a 'Duration' on the screen ? Emmanuel Lambert
                   ` (3 preceding siblings ...)
  1999-01-18  0:00 ` Emmanuel Lambert
@ 1999-01-18  0:00 ` robert_dewar
  4 siblings, 0 replies; 9+ messages in thread
From: robert_dewar @ 1999-01-18  0:00 UTC (permalink / raw)


In article <36A37529.69BFB3FF@cs.kuleuven.ac.be>,
  Emmanuel Lambert <Emmanuel.Lambert@cs.kuleuven.ac.be>
wrote:
> Hi,
>
> I am freaking out because I would like to output a
> variable from type Duration to the screen, but it does
> not work with put(...). I have included
> Ada.Float_Text_Io, but that does not help. Can someone
> give me a hint. I a unable to find good documentation on
> this.


Emmanuel, so that you may avoid freaking in the future,
let's help you to figure out how to find your own answer
next time :-)

First, look up type Duration in the reference manual, a
little searching in the RM (I always use the ASCII version
it is easier for me to search) finds:

  7   There is a predefined fixed point type named
      Duration, declared in the visible part of package
      Standard;

Ah ha! A *fixed point* type not a *floating point* type.
A little more spelunking around in Text_IO digs up:

68     generic
          type Num is delta <>;
       package Fixed_IO is

71        procedure Put(File : in File_Type;
                        Item : in Num;
                        Fore : in Field := Default_Fore;
                        Aft  : in Field := Default_Aft;
                        Exp  : in Field := Default_Exp);


and if you know how to use generics you are pretty much
home free now. But actually there is an even easier way,
and here again is how you could find this. Look up
operations on a fixed point type, and you will find the
Image attribute, just what the doctor ordered, now you
can do

   Put_Line (Duration'Image (xxx));

which is probably good enough for what you want, though
you don't have control over the format as you do with
Text_IO.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




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

* Re: Putting a 'Duration' on the screen ?
  1999-01-18  0:00 Putting a 'Duration' on the screen ? Emmanuel Lambert
  1999-01-18  0:00 ` Marin David Condic
  1999-01-18  0:00 ` Steve O'Neill
@ 1999-01-18  0:00 ` Tom Moran
  1999-01-18  0:00 ` Emmanuel Lambert
  1999-01-18  0:00 ` robert_dewar
  4 siblings, 0 replies; 9+ messages in thread
From: Tom Moran @ 1999-01-18  0:00 UTC (permalink / raw)


ada.text_io.put("That took" & duration'image(d) & "seconds");




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

* Re: Putting a 'Duration' on the screen ?
  1999-01-18  0:00 ` Marin David Condic
@ 1999-01-18  0:00   ` David C. Hoos, Sr.
  1999-01-18  0:00     ` Marin David Condic
  0 siblings, 1 reply; 9+ messages in thread
From: David C. Hoos, Sr. @ 1999-01-18  0:00 UTC (permalink / raw)



Marin David Condic wrote in message <36A38F05.EA6F4DD1@pwfl.com>...
<SNIP>
>where X above is declared to be of type Duration. The numeric types have
>the 'Image attribute which will return a string. See the ARM 3.5 (35)
>for a definition.
A slight correction -- all _scalar_ types have a 'image attribute.








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

* Re: Putting a 'Duration' on the screen ?
  1999-01-18  0:00   ` David C. Hoos, Sr.
@ 1999-01-18  0:00     ` Marin David Condic
  0 siblings, 0 replies; 9+ messages in thread
From: Marin David Condic @ 1999-01-18  0:00 UTC (permalink / raw)


David C. Hoos, Sr. wrote:
> 
> Marin David Condic wrote in message <36A38F05.EA6F4DD1@pwfl.com>...
> <SNIP>
> >where X above is declared to be of type Duration. The numeric types have
> >the 'Image attribute which will return a string. See the ARM 3.5 (35)
> >for a definition.
> A slight correction -- all _scalar_ types have a 'image attribute.

I stand corrected. Enumerations also include the 'Image attribute.

Anyway, it's the easiest way of getting something out to the screen -
especially when you're in a hurry and don't care too much about spacing.

I'm sure this question must be in the FAQ by now. But I suppose it won't
stop being asked since newbies are also frequently newbies to FAQs as
well. Maybe if CS profs made a little more effort to cover this, the
students wouldn't be so confused?

MDC
-- 
Marin David Condic
Real Time & Embedded Systems, Propulsion Systems Analysis
United Technologies, Pratt & Whitney, Large Military Engines
M/S 731-95, P.O.B. 109600, West Palm Beach, FL, 33410-9600
Ph: 561.796.8997         Fx: 561.796.4669
***To reply, remove "bogon" from the domain name.***

    "Nobody shot me."

        --  Last words of Frank Gusenberg when asked by police who
            shot him fourteen times with a machine gun in the Saint
            Valentine's Day Massacre.




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

* Putting a 'Duration' on the screen ?
@ 1999-01-18  0:00 Emmanuel Lambert
  1999-01-18  0:00 ` Marin David Condic
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Emmanuel Lambert @ 1999-01-18  0:00 UTC (permalink / raw)


Hi,

I am freaking out because I would like to output a variable from type
Duration to the screen, but it does not work with put(...). I have
included Ada.Float_Text_Io, but that does not help. Can someone give me
a hint. I a unable to find good documentation on this.

Thanks
Emmanuel Lambert







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

* Re: Putting a 'Duration' on the screen ?
  1999-01-18  0:00 Putting a 'Duration' on the screen ? Emmanuel Lambert
                   ` (2 preceding siblings ...)
  1999-01-18  0:00 ` Tom Moran
@ 1999-01-18  0:00 ` Emmanuel Lambert
  1999-01-18  0:00 ` robert_dewar
  4 siblings, 0 replies; 9+ messages in thread
From: Emmanuel Lambert @ 1999-01-18  0:00 UTC (permalink / raw)


Thanks to all for the valuable feedback!!







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

* Re: Putting a 'Duration' on the screen ?
  1999-01-18  0:00 ` Steve O'Neill
@ 1999-01-19  0:00   ` Matthew Heaney
  0 siblings, 0 replies; 9+ messages in thread
From: Matthew Heaney @ 1999-01-19  0:00 UTC (permalink / raw)


Steve O'Neill <oneills@top.monad.net> writes:

> Emmanuel Lambert wrote:
> 
> > I am freaking out because I would like to output a variable from type
> > Duration to the screen, but it does not work with put(...). I have
> > included Ada.Float_Text_Io, but that does not help. Can someone give me
> > a hint.
> 
> The hint is - Duration is not a floating point type, it's a fixed point
> type.  Either instantiate Fixed_IO for Duration or convert the duration
> object to float.

No, do not convert Duration to float.

You can either:

1) Use an instantiation of Ada.Text_IO.Fixed_IO; or

2) Use the attribute Duration'Image (X).

The 2nd option is easier.


-- 
Those who believe in the supernatural should be required to learn
computer programming.  This would force them to discover that things
which appear at first to be completely mysterious and incomprehensible,
in fact have a logical (and usually simple) explanation.  --J.B.R. Yant




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

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

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-01-18  0:00 Putting a 'Duration' on the screen ? Emmanuel Lambert
1999-01-18  0:00 ` Marin David Condic
1999-01-18  0:00   ` David C. Hoos, Sr.
1999-01-18  0:00     ` Marin David Condic
1999-01-18  0:00 ` Steve O'Neill
1999-01-19  0:00   ` Matthew Heaney
1999-01-18  0:00 ` Tom Moran
1999-01-18  0:00 ` Emmanuel Lambert
1999-01-18  0:00 ` robert_dewar

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