Exemplo n.º 1
0
 /// <summary>
 /// Determines whether the specified <paramref name="value"/> is hexadecimal.
 /// </summary>
 /// <param name="value">The string to verify is hexadecimal.</param>
 /// <returns><c>true</c> if the specified <paramref name="value"/> is hexadecimal; otherwise, <c>false</c>.</returns>
 public static bool IsHex(string value)
 {
     if (string.IsNullOrEmpty(value))
     {
         return(false);
     }
     if (!NumberUtility.IsEven(value.Length))
     {
         return(false);
     }
     using (StringReader reader = new StringReader(value))
     {
         int even = value.Length / 2;
         for (int i = 0; i < even; ++i)
         {
             char char1 = (char)reader.Read();
             char char2 = (char)reader.Read();
             if (!IsHexDigit(char1) || !IsHexDigit(char2))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
 /// <summary>
 /// Converts the specified <paramref name="bytes"/> to its equivalent representation in terabytes.
 /// </summary>
 /// <param name="bytes">The bytes to be converted.</param>
 /// <returns>A terabyte representation equivalent to the specified <paramref name="bytes"/>.</returns>
 public static double BytesToTerabytes(this long bytes)
 {
     return(NumberUtility.BytesToTerabytes(bytes));
 }
 /// <summary>
 /// Rounds a double-precision floating-point value to the nearest integral value closest to the specified <paramref name="accuracy"/>.
 /// </summary>
 /// <param name="value">A double-precision floating-point number to be rounded.</param>
 /// <param name="accuracy">The accuracy to use in the rounding.</param>
 /// <returns>
 /// The integer value closest to the specified <paramref name="accuracy"/> of <paramref name="value"/>.<br/>
 /// Note that this method returns a <see cref="double"/> instead of an integral type.
 /// </returns>
 public static double RoundOff(this double value, RoundOffAccuracy accuracy)
 {
     return(NumberUtility.RoundOff(value, accuracy));
 }
 /// <summary>
 /// Determines whether the specified <paramref name="value"/> is an odd number.
 /// </summary>
 /// <param name="value">The value to evaluate.</param>
 /// <returns><c>true</c> if the specified <paramref name="value"/> is an odd number; otherwise, <c>false</c>.</returns>
 public static bool IsOdd(this int value)
 {
     return(NumberUtility.IsOdd(value));
 }
 /// <summary>
 /// Determines whether the specified <paramref name="source"/> is a sequence of countable integrals (hence, integrals being either incremented or decremented with the same cardinality through out the sequence).
 /// </summary>
 /// <param name="source">The value to test for a sequence of countable characters.</param>
 /// <returns><c>true</c> if the specified <paramref name="source"/> is a sequence of countable integrals (hence, integrals being either incremented or decremented with the same cardinality through out the sequence); otherwise, <c>false</c>.</returns>
 public static bool IsCountableSequence(this IEnumerable <long> source)
 {
     return(NumberUtility.IsCountableSequence(source));
 }
 /// <summary>
 /// Calculates the factorial of a positive integer <paramref name="n"/> denoted by n!.
 /// </summary>
 /// <param name="n">The positive integer to calculate a factorial number by.</param>
 /// <returns>The factorial number calculated from <paramref name="n"/>, or <see cref="double.PositiveInfinity"/> if <paramref name="n"/> is to high a value.</returns>
 public static double Factorial(this double n)
 {
     return(NumberUtility.Factorial(n));
 }