Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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));
            }
        }