/// <summary> /// Return the string representation of the rational. /// </summary> /// <returns>The string representation of the rational.</returns> public override string ToString() { if (this._pointer == IntPtr.Zero) { return("uninitialized"); } char_ptr s_ptr = gmp_lib.mpq_get_str(char_ptr.Zero, 10, this); string s = s_ptr.ToString(); gmp_lib.free(s_ptr); return(s); }
public RandState(string value) { gmp_lib.gmp_randinit_default(Value); using (SHA256 sha = SHA256.Create()) { byte[] hash = sha.ComputeHash(Encoding.Default.GetBytes(value)); StringBuilder sb = new StringBuilder(); foreach (var h in hash) { sb.Append(h.ToString("X2")); } char_ptr tmpStr = new char_ptr(sb.ToString()); gmp_lib.mpz_init_set_str(Seed, tmpStr, 16); gmp_lib.gmp_randseed(Value, Seed); gmp_lib.free(tmpStr); } }
/// <summary> /// Return the string representation of the float. /// </summary> /// <returns>The string representation of the float.</returns> public override string ToString() { if (!_initialized) { return(null); } ptr <mp_exp_t> exp = new ptr <mp_exp_t>(0); char_ptr s_ptr = gmp_lib.mpf_get_str(char_ptr.Zero, exp, 10, 0, this); string s = s_ptr.ToString(); gmp_lib.free(s_ptr); if (s.StartsWith("-", StringComparison.Ordinal)) { return("-0." + s.Substring(1) + "e" + exp.Value.Value.ToString(System.Globalization.CultureInfo.InvariantCulture)); } else { return("0." + s + "e" + exp.Value.Value.ToString(System.Globalization.CultureInfo.InvariantCulture)); } }
/// <summary> /// Returns a value indicating whether this instance is equal to a specified <see cref="char_ptr">char_ptr</see> value. /// </summary> /// <param name="other">A <see cref="char_ptr">char_ptr</see> value to compare to this instance.</param> /// <returns><c>True</c> if <paramref name="other"/> has the same value as this instance; otherwise, <c>False</c>.</returns> public bool Equals(char_ptr other) { return(Pointer == other.Pointer); }