Browse Source

cmMath.h/c : Added cmModIncr().

master
kevin 8 years ago
parent
commit
01505d751a
2 changed files with 20 additions and 0 deletions
  1. 14
    0
      cmMath.c
  2. 6
    0
      cmMath.h

+ 14
- 0
cmMath.c View File

@@ -154,6 +154,20 @@ unsigned cmPrevOddU(  unsigned v ) { return cmIsOddU(v)  ? v : v-1; }
154 154
 unsigned cmNextEvenU( unsigned v ) { return cmIsEvenU(v) ? v : v+1; }
155 155
 unsigned cmPrevEvenU( unsigned v ) { return cmIsEvenU(v) ? v : v-1; }
156 156
 
157
+unsigned cmModIncr(int idx, int delta, int maxN )
158
+{
159
+  int sum = idx + delta;
160
+
161
+  if( sum >= maxN )
162
+    return sum - maxN;
163
+
164
+  if( sum < 0 )
165
+    return maxN + sum;
166
+
167
+  return sum;
168
+}
169
+
170
+
157 171
 // modified bessel function of first kind, order 0
158 172
 // ref: orfandis appendix B io.m
159 173
 double	cmBessel0( double x )

+ 6
- 0
cmMath.h View File

@@ -15,6 +15,12 @@ unsigned cmPrevOddU(  unsigned v );
15 15
 unsigned cmNextEvenU( unsigned v );
16 16
 unsigned cmPrevEvenU( unsigned v );
17 17
 
18
+/// Increment or decrement 'idx' by 'delta' always wrapping the result into the range
19
+/// 0 to (maxN-1).
20
+/// 'idx': initial value 
21
+/// 'delta':  incremental amount
22
+/// 'maxN' - 1 : maximum return value.
23
+unsigned cmModIncr(int idx, int delta, int maxN );
18 24
 
19 25
 // modified bessel function of first kind, order 0
20 26
 // ref: orfandis appendix B io.m

Loading…
Cancel
Save