Annotation of 43BSD/contrib/icon/operators/mod.c, revision 1.1

1.1     ! root        1: #include "../h/rt.h"
        !             2: 
        !             3: /*
        !             4:  * x % y - take remainder of x / y.
        !             5:  */
        !             6: 
        !             7: mod(nargs, arg2, arg1, arg0)
        !             8: int nargs;
        !             9: struct descrip arg2, arg1, arg0;
        !            10:    {
        !            11:    register int t1, t2;
        !            12:    union numeric n1, n2;
        !            13: 
        !            14:    SetBound;
        !            15:    /*
        !            16:     * x and y must be numeric.  Save the cvnum return values for later use.
        !            17:     */
        !            18:    if ((t1 = cvnum(&arg1, &n1)) == NULL)
        !            19:       runerr(102, &arg1);
        !            20:    if ((t2 = cvnum(&arg2, &n2)) == NULL)
        !            21:       runerr(102, &arg2);
        !            22: 
        !            23:    if (t1 == T_LONGINT && t2 == T_LONGINT) {
        !            24:       /*
        !            25:        * Both x and y are integers.  If y is 0, generate an error because
        !            26:        *  it's divide by 0.  Otherwise, just return the modulus of the
        !            27:        *  two arguments.
        !            28:        */
        !            29:       if (n2.integer == 0L)
        !            30:          runerr(202, &arg2);
        !            31:       mkint(n1.integer % n2.integer, &arg0);
        !            32:       }
        !            33:    else {
        !            34:       /*
        !            35:        * Either x or y is real, convert the other to a real, perform
        !            36:        *  the modulation, convert the result to an integer and place it
        !            37:        *  in arg0 as the return value.
        !            38:        */
        !            39:       if (t1 == T_LONGINT)
        !            40:          n1.real = n1.integer;
        !            41:       if (t2 == T_LONGINT)
        !            42:          n2.real = n2.integer;
        !            43:       mkreal(n1.real - n2.real * (int)(n1.real / n2.real), &arg0);
        !            44:       }
        !            45:    ClearBound;
        !            46:    }
        !            47: 
        !            48: Opblock(mod,2,"%")

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.