Newbie questions: real-to->int, getting time for seed
Author Message
Newbie questions: real-to->int, getting time for seed

I have just started with MacOberon.

For some reason I found it very difficult to find
a function to convert a Real to an Integer.
I ended up doing SHORT(ENTIER(realNum)).
Surely there is a round and a trunc. function somewhere which
will do the job.

The other thing I wanted to do was use a function which would
return the system time in seconds (for use as a random seed).
I know System.Time will print it out to the log window for me
but I want it just returned as a function result.

--tim
--
--------------------------------------------------------

/ Computer Science Department, Monash Uni (Clayton), Australia \
|________________________________________________________________|

Tue, 21 May 1996 15:11:41 GMT
Newbie questions: real-to->int, getting time for seed
: I have just started with MacOberon.

: For some reason I found it very difficult to find
: a function to convert a Real to an Integer.
: I ended up doing SHORT(ENTIER(realNum)).
: Surely there is a round and a trunc. function somewhere which
: will do the job.

ENTIER is the correct way to doit. See the manual for its
definition. The other rounding functions such as bankers
rounding can be derived from ENTIER.

PROCEDURE Round( x : REAL ):LONGINT;
BEGIN
RETURN ENTIER( x + 0.5 );
END Round.

: The other thing I wanted to do was use a function which would
: return the system time in seconds (for use as a random seed).
: I know System.Time will print it out to the log window for me
: but I want it just returned as a function result.

Oberon.Time()

Whitney

Tue, 21 May 1996 22:07:42 GMT
Newbie questions: real-to->int, getting time for seed

Quote:

>I have just started with MacOberon.

>For some reason I found it very difficult to find
>a function to convert a Real to an Integer.
>I ended up doing SHORT(ENTIER(realNum)).
>Surely there is a round and a trunc. function somewhere which
>will do the job.

The ETH implementations of Oberon interpret ENTIER as
being the flooring function.  However, as I recall, the
language definition does not specify whether ENTIER should be
floor, truncate, or Euclidean.

Quote:

>The other thing I wanted to do was use a function which would
>return the system time in seconds (for use as a random seed).
>I know System.Time will print it out to the log window for me
>but I want it just returned as a function result.

According to the file OberonGuide.Text, Input.Time
will return the system time units of 1/300 second.  There is
another date/time function documented in _The Oberon System_
by Reiser.

All this information is available if you have ETH's
Oberon system, you just need a little patience to look for it.

M

--
___
(o o)
-----------------------------ooO-(_)-Ooo-----------------------------

Thu, 23 May 1996 15:42:30 GMT
Newbie questions: real-to->int, getting time for seed

Quote:

>        The ETH implementations of Oberon interpret ENTIER as
>being the flooring function.  However, as I recall, the
>language definition does not specify whether ENTIER should be
>floor, truncate, or Euclidean.

From the Oberon2.Report.Text:

Name        Argument type   Result type   Function
ENTIER(x)   real type       LONGINT       largest integer not greater than x

Quote:
>        According to the file OberonGuide.Text, Input.Time
>will return the system time units of 1/300 second.  There is
>another date/time function documented in _The Oberon System_
>by Reiser.

On all Unix-ports, TimeUnit is 1/1000th of a second. On MacOberon and DOSOberon
it is 1/300th.

Institute for Computer Systems
Swiss Federal Institute of Technology (ETH)
Zurich, Switzerland

Sat, 25 May 1996 19:52:31 GMT

 Page 1 of 1 [ 4 post ]

Relevant Pages