Dec.28.2018 -- CAlive to add operator -%, a range-aware modulo operator

13 views
Skip to first unread message

Rick C. Hodgin

unread,
Dec 28, 2018, 9:25:08 AM12/28/18
to CAlive Programming Language
CAlive will introduce a new range-aware modulo operator using -%.  This new operator will use the positive % operator using the same pattern as is seen in positive integers even when the input goes negative.  It performs the following range_modulo() operation:

    // v=value, m=modulo number
    function range_modulo
    | params int v, int m
    | returns r
    {
        if (v >= 0)    r = v % m;
        else           r = (m + (v % m)) % m;
    }


    // Use in code
    function main
    | params int argc, char* argv[]
    {
        for (int i = 12; i > -22; --i)
        {
            printf("%d --> range_modulo = (%d), -% = (%d)\n",
                   i,
                   range_modulo(i, 10),
                   i -% 10);
        }
    }

-- 
Rick C. Hodgin

Reply all
Reply to author
Forward
0 new messages