C implementation of the Octave/Matlab unwrap function

The unwrap function in Octave/Matlab is simplifying the modulo of an arrray. It's an easy piece of code but handy to have it around off the shelf:

unwrap.c
int unwrap(int *values, int numberOfValues, int modulo)//modulo = 360
{
    int add = 0;
    for (int i = 1; i < numberOfValues; i++)
    {
        while(abs(values[i-1] - values[i])  > modulo/2)
        {
            (values[i-1] > values[i]) ? add += modulo : add -= modulo; //could be faster if i kept the phase between samples
            values[i] += add;                                          // but longer and less easy to read, in case of perfomance
        }                                                              // issue, there's probably a way to scrape a few cycles here
        add = 0;
    }
}