Ver código fonte

cmMath.h/c : Added cmModIncr().

master
kevin 9 anos atrás
pai
commit
01505d751a
2 arquivos alterados com 20 adições e 0 exclusões
  1. 14
    0
      cmMath.c
  2. 6
    0
      cmMath.h

+ 14
- 0
cmMath.c Ver arquivo

@@ -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 Ver arquivo

@@ -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

Carregando…
Cancelar
Salvar