Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

/ (divide)

 Keyword Abbreviation Token (hex) Version(s) Classification / none AD 1.0 to 7.0 Operator (2)

dividend / divisor

 Parameters Type Legal Value(s) Default Value Note(s) dividend Numeric any also called the numerator divisor Numeric any but zero also called the denominator

 Returns Type Value(s) Note(s) quotient Numeric any

 Purpose
Calculate an arithmetic expression.

 Remarks
The divide operator calculates the quotient of any two real numbers, except for a zero divisor.  I'm not going to explain how division works; take a class in Elementry School if you need help.  Attempting to use zero for the divisor generates a DIVISION BY ZERO ERROR.

If the absolute value of the result is greater than 1.70141183e+38 then an OVERLOW ERROR occurs.  If the absolute value of the result is less than 2.93873588e-39 then it silently underflows to zero.

The divide operator has the second-highest fixed priority (the same as mulitply, but lower than power).  The user of course may over-ride the built-in operator priorities by using parentheses "(" and ")".

Like all operators, the result may be printed, stored in an appropriate variable, or combined with other operators in a larger expression.  In this case, a numeric variable is required for storage.  But if the variable is an integer, the minimum result that can be stored is -32768 and the maximum is +32767; otherwise an ILLEGAL QUANTITY ERROR is generated.

Some versions of BASIC, and many other languages, include a handy operator called something like modulus. That value is just the remainder after dividing to integer accuracy.  CBM BASIC does not have this feature, so here's how you can do it:
 ```Q = INT( N / D) : REM integer quotient R = N - Q * D : REM remainder ```

With that code, R will be an integer if both N and D are integers. Otherwise, R will probably not be an integer either. In any case, R should be less than D.

CBM BASIC (nor any langauge now that I think about) really has a "string division" operator.  But CBM BASIC v3.5 and v7.0 offer the INSTR function which at least gives you the answer of "does it go into"...

 Compare With

 Contrast With
^, *+