@@ -113,11 +113,11 @@ public static void FileExists(string path)
113113 public static void IsWithinArrayBounds ( int index , int arrayLength )
114114 {
115115#if BOUNDS_CHECKS
116- IsNotSmaller ( arrayLength , 0 ) ;
116+ IsNonNegative ( arrayLength ) ;
117117
118118 if ( ( uint ) index >= ( uint ) arrayLength )
119119 {
120- throw new IndexOutOfRangeException ( $ "{ index } out of range (length { arrayLength } - 1).") ;
120+ throw new IndexOutOfRangeException ( $ "{ index } is out of range (length { arrayLength } - 1).") ;
121121 }
122122#endif
123123 }
@@ -130,11 +130,11 @@ public static void IsValidSubarray(int index, int NumEntries, int arrayLength)
130130 {
131131#if SUBARRAY_CHECKS
132132 IsWithinArrayBounds ( index , arrayLength ) ;
133- IsNotSmaller ( NumEntries , 0 ) ;
133+ IsNonNegative ( NumEntries ) ;
134134
135135 if ( index + NumEntries > arrayLength )
136136 {
137- throw new IndexOutOfRangeException ( $ "index + NumEntries is { index + NumEntries } , which is larger than length { arrayLength } .") ;
137+ throw new IndexOutOfRangeException ( $ "{ nameof ( index ) } + { nameof ( NumEntries ) } is { index + NumEntries } , which is larger than length { arrayLength } .") ;
138138 }
139139#endif
140140 }
@@ -164,6 +164,197 @@ public static void SubarraysDoNotOverlap(int firstIndex, int secondIndex, int fi
164164
165165
166166 #region COMPARE_CHECKS
167+ /// <summary> Remember: Zero is neither positive nor negative. </summary>
168+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
169+ public static void IsPositive ( long value )
170+ {
171+ #if COMPARE_CHECKS
172+ if ( value <= 0 )
173+ {
174+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be positive.") ;
175+ }
176+ #endif
177+ }
178+
179+ /// <summary> Remember: Zero is neither positive nor negative. </summary>
180+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
181+ public static void IsPositive ( float value )
182+ {
183+
184+ #if COMPARE_CHECKS
185+ if ( value <= 0f )
186+ {
187+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be positive.") ;
188+ }
189+ #endif
190+ }
191+
192+ /// <summary> Remember: Zero is neither positive nor negative. </summary>
193+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
194+ public static void IsPositive ( double value )
195+ {
196+
197+ #if COMPARE_CHECKS
198+ if ( value <= 0d )
199+ {
200+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be positive.") ;
201+ }
202+ #endif
203+ }
204+
205+ /// <summary> Remember: Zero is neither positive nor negative. </summary>
206+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
207+ public static void IsPositive ( decimal value )
208+ {
209+ #if COMPARE_CHECKS
210+ if ( value <= 0m )
211+ {
212+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be positive.") ;
213+ }
214+ #endif
215+ }
216+
217+ /// <summary> Remember: Zero is neither positive nor negative. </summary>
218+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
219+ public static void IsNegative ( long value )
220+ {
221+ #if COMPARE_CHECKS
222+ if ( value >= 0 )
223+ {
224+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be negative.") ;
225+ }
226+ #endif
227+ }
228+
229+ /// <summary> Remember: Zero is neither positive nor negative. </summary>
230+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
231+ public static void IsNegative ( float value )
232+ {
233+
234+ #if COMPARE_CHECKS
235+ if ( value <= 0f )
236+ {
237+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be negative.") ;
238+ }
239+ #endif
240+ }
241+
242+ /// <summary> Remember: Zero is neither positive nor negative. </summary>
243+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
244+ public static void IsNegative ( double value )
245+ {
246+
247+ #if COMPARE_CHECKS
248+ if ( value <= 0d )
249+ {
250+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be negative.") ;
251+ }
252+ #endif
253+ }
254+
255+ /// <summary> Remember: Zero is neither positive nor negative. </summary>
256+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
257+ public static void IsNegative ( decimal value )
258+ {
259+ #if COMPARE_CHECKS
260+ if ( value <= 0m )
261+ {
262+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be negative.") ;
263+ }
264+ #endif
265+ }
266+
267+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
268+ public static void IsNonNegative ( long value )
269+ {
270+ #if COMPARE_CHECKS
271+ if ( value < 0 )
272+ {
273+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be positive or equal to zero.") ;
274+ }
275+ #endif
276+ }
277+
278+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
279+ public static void IsNonNegative ( float value )
280+ {
281+
282+ #if COMPARE_CHECKS
283+ if ( value < 0f )
284+ {
285+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be positive or equal to zero.") ;
286+ }
287+ #endif
288+ }
289+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
290+ public static void IsNonNegative ( double value )
291+ {
292+
293+ #if COMPARE_CHECKS
294+ if ( value < 0d )
295+ {
296+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be positive or equal to zero.") ;
297+ }
298+ #endif
299+ }
300+
301+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
302+ public static void IsNonNegative ( decimal value )
303+ {
304+ #if COMPARE_CHECKS
305+ if ( value < 0m )
306+ {
307+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be positive or equal to zero.") ;
308+ }
309+ #endif
310+ }
311+
312+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
313+ public static void IsNotPositive ( long value )
314+ {
315+ #if COMPARE_CHECKS
316+ if ( value > 0 )
317+ {
318+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be negative or equal to zero.") ;
319+ }
320+ #endif
321+ }
322+
323+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
324+ public static void IsNotPositive ( float value )
325+ {
326+
327+ #if COMPARE_CHECKS
328+ if ( value > 0f )
329+ {
330+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be negative or equal to zero.") ;
331+ }
332+ #endif
333+ }
334+
335+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
336+ public static void IsNotPositive ( double value )
337+ {
338+
339+ #if COMPARE_CHECKS
340+ if ( value > 0d )
341+ {
342+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be negative or equal to zero.") ;
343+ }
344+ #endif
345+ }
346+
347+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
348+ public static void IsNotPositive ( decimal value )
349+ {
350+ #if COMPARE_CHECKS
351+ if ( value > 0m )
352+ {
353+ throw new ArgumentOutOfRangeException ( $ "{ value } was expected to be negative or equal to zero.") ;
354+ }
355+ #endif
356+ }
357+
167358 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
168359 public static void AreEqual < T > ( T a , T b )
169360 where T : IEquatable < T >
0 commit comments