Thread: One line power
View Single Post
  #8   Spotlight this post!  
Unread 05-03-2002, 00:24
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
MIN and MAX

Quote:
Originally posted by Ian W.
also, what does "min" or "max" mean?
In PBASIC, MIN and MAX are somewhat counterintuitive. (That means they work differently than you might expect. )

Other languages have MIN and MAX functions which compare two (or more) operands, and return the smallest (or largest) value. In PBASIC, the operation is actually exactly the opposite! MIN returns the larger of two values, and MAX returns the smaller!

But it isn't really that confusing. Just think of it as "clamping" the minimum and/or maximum values of a variable or calculation. For example, X = X MIN 10 will leave X unchanged as long as it is greater than (or equal to) 10. However, if its value drops below 10, it is set to 10 instead. MAX works similarly.

BUT BE CAREFUL! MIN 0 DOESN'T DO ANYTHING! You might think that it would prevent the result of a calculation from going negative, but you'd be wrong! MIN and MAX only work with positive numbers, and if you try to give them negative numbers, they will look at them as very large positive numbers! (The reason for this is that the BS2 stores negative numbers in twos complement form. See this message for a very concise description of how twos complements work.)
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me

Last edited by Greg Ross : 05-03-2002 at 00:33.