This shows you the differences between two versions of the page.
— |
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, | ||
+ | { | ||
+ | for (int i = 0; i < numberOfValues; | ||
+ | { | ||
+ | while(values[i] > modulo/2 || values[i] < modulo/2) | ||
+ | { | ||
+ | (values[i] > modulo/2) ? values[i] -= modulo : values[i] += modulo; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ |