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

1.1     ! root        1: #include "../h/rt.h"
        !             2: 
        !             3: /*
        !             4:  * -x - negate x.
        !             5:  */
        !             6: 
        !             7: neg(nargs, arg1, arg0)
        !             8: int nargs;
        !             9: struct descrip arg1, arg0;
        !            10:    {
        !            11:    DclSave
        !            12:    union numeric n;
        !            13:    long l;
        !            14: 
        !            15:    SetBound;
        !            16:    /*
        !            17:     * x must be numeric.
        !            18:     */
        !            19:    switch (cvnum(&arg1, &n)) {
        !            20:       case T_LONGINT:
        !            21:          /*
        !            22:           * If it's an integer, check for overflow by negating it and
        !            23:           *  seeing if the negation didn't "work".  Use mkint to
        !            24:           *  construct the return value.
        !            25:           */
        !            26:          l = -n.integer;
        !            27:          if (n.integer < 0 && l < 0)
        !            28:             runerr(203, &arg1);
        !            29:          mkint(l, &arg0);
        !            30:          break;
        !            31: 
        !            32:       case T_REAL:
        !            33:          /*
        !            34:           * x is real, just negate it and use mkreal to construct the
        !            35:           *  return value.
        !            36:           */
        !            37:          mkreal(-n.real, &arg0);
        !            38:          break;
        !            39: 
        !            40:       default:
        !            41:          /*
        !            42:           * x isn't numeric.
        !            43:           */
        !            44:          runerr(102, &arg1);
        !            45:       }
        !            46:    ClearBound;
        !            47:    }
        !            48: 
        !            49: Opblock(neg,1,"-")

unix.superglobalmegacorp.com

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