To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 170
169  |  171
Subject: 
Re: NQC 2.0 and some math questions
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Thu, 30 Sep 1999 06:01:04 GMT
Viewed: 
2262 times
  
In article <37f16547.6612368@lugnet.com>, marcob@equalis.it wrote:

x = y % z

is equivalent to (where w is an temporary integer):

w = y / z;
x = y - z * w;


That's exaclty what I was thinking of doing.  Originally, the compiler had
no way of allocating temp variables which is why code for % couldn't be
emitted.  The temp allocator is now pretty good, so I could emit the above
sequence, but it just didn't occur to me until a few days ago.

There is one subtle problem.  The operations above won't happen
atomically, so there are some concurrency issues.  To be completely safe,
I'd have to latch both y and z into temps as well.  Without this, some
truly weird stuff can happen.  For example, lets say that intially y is a
multiple of z, and then you decrement y in-between the computation of w
and x.  The result will be that x is negative.  This is a result that is
inconsistient with the decrement happening either before or after the
entire mod calculation.

My personal feeling on this, however, is that if you're running around
changing y amd z in one task while calculating with them in another,
you're just asking for trouble.

Dave Baum

--
reply to: dbaum at enteract dot com



Message has 2 Replies:
  Re: NQC 2.0 and some math questions
 
(...) I think that if you do something like this you should use a semaphore to secure no tasks access y and z simultanously. But that wastes another variable storing the sema. (25 years ago, 30-Sep-99, to lugnet.robotics.rcx.nqc)
  Sharing variables and using expressions (was Re: NQC 2.0 and some math questions
 
I have discovered a somewhat non-intuitive feature of NQC (in my version, at least, which is pre-2.0) The statement: var = (20 * var) / 21; gets compiled into the following: MUL var, 20 ; var = var * 20 DIV var, 21 ; var = var / 21 rather than the (...) (25 years ago, 19-Oct-99, to lugnet.robotics.rcx.nqc)

Message is in Reply To:
  Re: NQC 2.0 and some math questions
 
(...) x = y % z is equivalent to (where w is an temporary integer): w = y / z; x = y - z * w; I can't think of a useful use of % just with constants. Ciao. Marco. (25 years ago, 29-Sep-99, to lugnet.robotics.rcx.nqc)

16 Messages in This Thread:




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

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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