Pārlūkot izejas kodu

cmMath.h/c : Added cmModIncr().

master
kevin 9 gadus atpakaļ
vecāks
revīzija
01505d751a
2 mainītis faili ar 20 papildinājumiem un 0 dzēšanām
  1. 14
    0
      cmMath.c
  2. 6
    0
      cmMath.h

+ 14
- 0
cmMath.c Parādīt failu

@@ -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 Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt