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.)