Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>mod() modulus of two numbers examplep.prg</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Mod()          Modulus of two numbers                  Examplep.prg


Syntax:        Mod(<expN1>, <expN2>)

Argument:      <expN1> is the dividend of the division operation.

               <expN2> is the divisor of the division operation.

Returns:       A numeric value.

               Mod() returns a number representing the remainder of
               <expN1> divided by <expN2>.

Notes:         Mod() emulates the dBASE III PLUS MOD() function using
               the Clipper modulus operator (%).  Note, however, there
               are differences between the dBASE III PLUS MOD() function
               and the Clipper modulus operator.  The following table
               below describes the differences:

               Table: Differences Between dBASE III PLUS MOD()
               Function and the Clipper Modulus Operator
               ---------------------------------------------------
                                 Modulus            dBASE III PLUS
               Dividend Divisor  Operator   Mod()   MOD() function
               ---------------------------------------------------
                   3        0      Error     Error       3
                   3       -2        1        -1        -1
                  -3        2       -1         1         1
                  -3        0      Error      Error     -3
                  -1        3       -1         2         2
                  -2        3       -2         1         1
                   2       -3        2        -1        -1
                   1       -3        1        -2        -2
               ---------------------------------------------------

Notes:         . In dBASE III PLUS, a zero divisor returns the dividend
                 for every value of the dividend.  In Clipper, by
                 contrast, the modulus of a any dividend using a zero
                 divisor causes an Expression error.

               . In versions of Clipper prior to Summer '87, a modulus
                 operation with a zero divisor returned zero for all
                 dividends.  In Summer '87, it returns an Expression
                 error.  To restore the previous behavior, place the
                 following block of code in your Expr_error() error
                 function:

                     IF M->info = "zero divide" .AND. "%" $ M->model
                        RETURN 0
                     END

Library:       EXTEND.LIB


--------------------------------- Source Code ------------------------------

   FUNCTION Mod
   PARAMETERS cl_num, cl_base
   PRIVATE cl_result
   *
   cl_result = cl_num % cl_base
   RETURN IF(cl_base = 0, cl_num,;
            IF(cl_result * cl_base < 0, cl_result + cl_base,
               cl_result))

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson