Go to Post If you want to have other teams cheer for you all day long at competition, name your team "Robot Coming Through". - Gary Dillard [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-03-2004, 10:48
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: syntax in c???

% is usually called the "mod" or "modulus" operator, but that means the same thing as remainder.

A couple of things to be careful of. The behavior of % with negative operands is not standardized. In
Code:
( a % b )
if a or b is negative, C only guarantees that the absolute value of the result will be less than b. Better make sure the numbers are positive. One way to do this is to add a multiple of the second operand to the first operand. But be careful of precedence.

The order of precedence of '%' is the same as for '*' and '/', which is higher than for '+' and '-'. So
Code:
( ii + 16 % 8 )
evaluates the same as
Code:
(ii + 0)
which is just
Code:
(ii)
Use parens to get what you want:
Code:
( (ii+16) % 8 )
It also makes for more readable code.

-norm
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
BS2 syntax (PBASIC) on the new controllers? Maybe! Jeremy_Mc Programming 0 25-10-2003 15:00
PBASIC Syntax Question Raven_Writer Programming 4 20-08-2003 08:07
PBASIC language syntax WizardOfAz Programming 14 30-04-2003 10:23
Pbasic 2.5 syntax Rickertsen2 Programming 10 15-02-2003 08:56
UltraEdit Syntax Highlighting Jeff McCune Programming 9 19-01-2003 20:08


All times are GMT -5. The time now is 03:07.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi