Beispiel #1
0
 /// <summary>
 /// Creates an integer from a string.
 /// </summary>
 public GmpInteger(string initialValue)
 {
     if (string.IsNullOrWhiteSpace(initialValue))
     {
         throw new ArgumentException("initialValue");
     }
     Interop.mpz_set_str(ref _Storage, initialValue, 10);
     DisposeContext.AddDisposeObject(this);
 }
Beispiel #2
0
 /// <summary>
 /// Create a new integer, importing it from an array of input values and setting the sign.
 /// The most significant byte is given first.
 /// This option is here for saving and loading the integer.
 /// The sign is specified seperately because GMP uses magnitude/sign format.
 /// </summary>
 public GmpInteger(byte[] initialValue, bool isNegative = false)
 {
     if (initialValue == null)
     {
         throw new ArgumentException("initialValue");
     }
     Interop.mpz_import(ref _Storage, initialValue.Length, 1, 1, 0, 0, initialValue);
     if (isNegative)
     {
         mpz_t negStorage = new mpz_t();
         Interop.mpz_neg(ref negStorage, ref _Storage);
         Interop.mpz_clear(ref _Storage);
         _Storage = negStorage;
     }
     DisposeContext.AddDisposeObject(this);
 }
Beispiel #3
0
 /// <summary>
 /// Initialize a zero valued integer.
 /// </summary>
 public GmpInteger()
 {
     Interop.mpz_init(ref _Storage);
     DisposeContext.AddDisposeObject(this);
 }