To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 1691
1690  |  1692
Subject: 
Re:system time
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Mon, 17 Mar 1997 16:18:43 GMT
Original-From: 
rabbit <g-webb@students.uiuc!saynotospam!.edu>
Viewed: 
1703 times
  
On Mon, 17 Mar 1997, Joe Martin wrote:

Pandit,
As far as I know I can only read system time as along integer or floating
point number(both cannot be used in conditionals).I do not know what
casting is.One idea I came up with is creating process which runs for one
millisecond and putting it in a loop,every time that the process runs it
adds one to itself and therefore returns a count in milliseconds from the
time the process begins for the first time.By using integers in the
mathematics involved in the process you end up with a time count that can
be used in a conditional.

Since the system time is already provided, creating a process
which runs every millisecond to achieve this may not be in your best
interest, and will probably slow things down quite a bit.  I dont recall
whether the system clock counts in milliseconds or seconds but if you
simply cast the system time to an integer you should be able to use it in
a conditional.  'Casting' means that you take one data type and force it
to be another.  For instance, if we were to cast a floating point to an
integer, the floating point number '2.3456' would become '2'.  Going the
other way the integer '2' would become '2.0'.  In the case of casting a
float to an int, the number is truncated.
The syntax of casting is very simple and straight forward.
Define two variables:

int i;
float f = 2.345;

And cast the float to an int:

i = (int)f;  /* 'i' is now '2'

Whatever data type is in the parenthesis is to what the variable will be
cast.  This works for assigning constants to variables as well.
If the system time returns a decimal number (I dont recall right
now what it returns) which you do not want truncated, simply multiply the
floating point number by a power of 10 before casting.  For instance if
the system time is 11.243 in seconds, convert it to milliseconds by
multiplying by 1000 and then cast:

systime = 11.243;
i=(int)(systime*1000);   /* 'i' will now equals '11243' */

Any expression involving only constants will automatically be cast to
whatever type you are assigning;

i=22/7;  /* This expression evaluates to '3.14...' but will be
    cast to '3' */

I hope this eliminates some of the confusion regarding type casting.  If
not please let me know.


Garth Webb



Message is in Reply To:
  Re:system time
 
Pandit, As far as I know I can only read system time as along integer or floating point number(both cannot be used in conditionals).I do not know what casting is.One idea I came up with is creating process which runs for one millisecond and putting (...) (28 years ago, 17-Mar-97, to lugnet.robotics.handyboard)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR