Microsoft.Scripting.Math.BigInteger.AsInt32 C# (CSharp) Method

AsInt32() public method

public AsInt32 ( int &ret ) : bool
ret int
return bool
    public bool AsInt32(out int ret) {
      ret = 0;
      if (sign == 0) return true;
      if (Length > 1) return false;
      if (data[0] > 0x80000000) return false;
      if (data[0] == 0x80000000 && sign == 1) return false;
      ret = (int)data[0];
      ret *= sign;
      return true;
    }

Usage Example

Example #1
0
 /// <summary>
 /// Converts a BigInteger to int if it is small enough
 /// </summary>
 /// <param name="x">The value to convert</param>
 /// <returns>An int if x is small enough, otherwise x.</returns>
 /// <remarks>
 /// Use this helper to downgrade BigIntegers as necessary.
 /// </remarks>
 public static object/*!*/ Normalize(BigInteger/*!*/ x) {
     int result;
     if (x.AsInt32(out result)) {
         return ScriptingRuntimeHelpers.Int32ToObject(result);
     }
     return x;
 }
All Usage Examples Of Microsoft.Scripting.Math.BigInteger::AsInt32