User Tools

Site Tools


implementation_modulo

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

implementation_modulo [2018/09/19 17:10] (current)
supergnu created
Line 1: Line 1:
 +====== C implementation of a modulo function ======
  
 +It's an easy piece of code but handy to have it around off the shelf:
 +<code C modulo.c>​
 +int modulo(int *values, int numberOfValues,​ int modulo)
 +{
 +    for (int i = 0; i < numberOfValues;​ i++)
 +    {
 +        while(values[i] > modulo/2 || values[i] < modulo/2)
 +        {
 +            (values[i] > modulo/2) ? values[i] -= modulo : values[i] += modulo;
 +        }
 +    }
 +}
 +</​code>​
implementation_modulo.txt ยท Last modified: 2018/09/19 17:10 by supergnu