Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FYI: Converting TIME to INTEGER

4,607 views
Skip to first unread message

Jaroslaw Kaczynski

unread,
Jul 9, 1999, 3:00:00 AM7/9/99
to
I have received the question 'How to convert time value to integer or real
value?'
from my customer. I have checked some resources and the answer is
not immediately obvious, so I thought it may be useful to post it here...

There are two simple ways of doing it:
1. Official way : use 'POS attribute
Please remember that the base unit of the TIME type is fs, so
TIME'POS(10 ns)
should return 10_000_000. If you need real type value, you can
use typecasting ( REAL(TIME'POS(10 ns)) ).

2. Very neat shortcut: divide time value by any time unit
Very convenient if you need the resulting integer to represent
number of nanoseconds or picoseconds;
10 ns / 1 ps
gives 10_000

Andreas Gieriet

unread,
Jul 10, 1999, 3:00:00 AM7/10/99
to Jaroslaw Kaczynski
Jaroslaw Kaczynski wrote:
>
> I have received the question 'How to convert time value to integer or real
> value?'
> from my customer. I have checked some resources and the answer is
> not immediately obvious, so I thought it may be useful to post it here...
>
> There are two simple ways of doing it:
> 1. Official way : use 'POS attribute
> Please remember that the base unit of the TIME type is fs, so
> TIME'POS(10 ns)
> should return 10_000_000. If you need real type value, you can
> use typecasting ( REAL(TIME'POS(10 ns)) ).

From my experience, this is not the case:
time'pos(10 ns) returns 10 if you set the time unit to 'ns'
(please correct me if I'm wrong).

>
> 2. Very neat shortcut: divide time value by any time unit
> Very convenient if you need the resulting integer to represent
> number of nanoseconds or picoseconds;
> 10 ns / 1 ps
> gives 10_000

The easiest way to get a 'time as integer' in the given time unit is:

10 ns / time'val(1)

which would give 10 if you select 'ns' as time unit or 10_000_000
if you select 'fs' as time unit.

--
Andreas Gieriet
http://www.diagonal.ch/

0 new messages