示例#1
0
            private static string FormatExponential(BigDouble value, int places)
            {
                if (value.Exponent <= -ExpLimit || IsZero(value.Mantissa))
                {
                    return("0" + (places > 0 ? ".".PadRight(places + 1, '0') : "") + "E+0");
                }

                var len       = (places >= 0 ? places : MaxSignificantDigits) + 1;
                var numDigits = (int)Math.Ceiling(Math.Log10(Math.Abs(value.Mantissa)));
                var rounded   = Math.Round(value.Mantissa * Math.Pow(10, len - numDigits)) * Math.Pow(10, numDigits - len);

                var mantissa = ToFixed(rounded, Math.Max(len - numDigits, 0));

                if (mantissa != "0" && places < 0)
                {
                    mantissa = mantissa.TrimEnd('0', '.');
                }
                return(mantissa + "E" + (value.Exponent >= 0 ? "+" : "")
                       + value.Exponent);
            }
示例#2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            const float gapWidth     = 10;
            var         mantissaRect = new Rect(position.x, position.y, (position.width - gapWidth) * 0.66f, position.height);
            var         gapRect      = new Rect(mantissaRect.x + mantissaRect.width, position.y, gapWidth, position.height);
            var         exponentRect = new Rect(gapRect.x + gapRect.width, position.y, (position.width - gapWidth) * 0.33f,
                                                position.height);

            var mantissaProperty = property.FindPropertyRelative("mantissa");
            var exponentProperty = property.FindPropertyRelative("exponent");

            EditorGUI.BeginChangeCheck();
            var mantissa = EditorGUI.DoubleField(mantissaRect, mantissaProperty.doubleValue,
                                                 new GUIStyle(EditorStyles.numberField)
            {
                alignment = TextAnchor.MiddleRight
            });

            EditorGUI.LabelField(gapRect, "e", new GUIStyle(GUIStyle.none)
            {
                alignment = TextAnchor.MiddleCenter
            });
            var exponent = EditorGUI.LongField(exponentRect, exponentProperty.longValue);

            if (EditorGUI.EndChangeCheck())
            {
                var normalized = BigDouble.Normalize(mantissa, exponent);
                mantissaProperty.doubleValue = normalized.Mantissa;
                exponentProperty.longValue   = normalized.Exponent;
            }

            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
示例#3
0
 public static int Sign(this BigDouble value)
 {
     return(BigDouble.Sign(value));
 }
示例#4
0
 /// <summary>
 /// Joke function from Realm Grinder.
 /// </summary>
 public static BigDouble AscensionPenalty(this BigDouble value, double ascensions)
 {
     return(Math.Abs(ascensions) < double.Epsilon ? value : BigDouble.Pow(value, Math.Pow(10, -ascensions)));
 }
示例#5
0
 public static BigDouble Cbrt(this BigDouble value)
 {
     return(BigDouble.Cbrt(value));
 }
示例#6
0
 public static BigDouble Factorial(this BigDouble value)
 {
     return(BigDouble.Factorial(value));
 }
示例#7
0
 public static double Atanh(this BigDouble value)
 {
     return(BigDouble.Atanh(value));
 }
示例#8
0
 public static BigDouble Cosh(this BigDouble value)
 {
     return(BigDouble.Cosh(value));
 }
示例#9
0
 public static BigDouble Multiply(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Multiply(value, other));
 }
示例#10
0
 public static BigDouble Subtract(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Subtract(value, other));
 }
示例#11
0
 public static BigDouble Add(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Add(value, other));
 }
示例#12
0
 public static BigDouble Truncate(this BigDouble value)
 {
     return(BigDouble.Truncate(value));
 }
示例#13
0
 public static BigDouble Ceiling(this BigDouble value)
 {
     return(BigDouble.Ceiling(value));
 }
示例#14
0
 public static BigDouble Floor(this BigDouble value)
 {
     return(BigDouble.Floor(value));
 }
示例#15
0
 public static BigDouble Round(this BigDouble value)
 {
     return(BigDouble.Round(value));
 }
示例#16
0
 public static BigDouble Exp(this BigDouble value)
 {
     return(BigDouble.Exp(value));
 }
示例#17
0
 public static BigDouble Sinh(this BigDouble value)
 {
     return(BigDouble.Sinh(value));
 }
示例#18
0
 public static BigDouble Divide(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Divide(value, other));
 }
示例#19
0
 public static BigDouble Tanh(this BigDouble value)
 {
     return(BigDouble.Tanh(value));
 }
示例#20
0
 public static BigDouble Reciprocate(this BigDouble value)
 {
     return(BigDouble.Reciprocate(value));
 }
示例#21
0
 public static BigDouble Pow(this BigDouble value, double power)
 {
     return(BigDouble.Pow(value, power));
 }
示例#22
0
 public static BigDouble Min(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Min(value, other));
 }
示例#23
0
 public static BigDouble Sqrt(this BigDouble value)
 {
     return(BigDouble.Sqrt(value));
 }
示例#24
0
 public static double AbsLog10(this BigDouble value)
 {
     return(BigDouble.AbsLog10(value));
 }
示例#25
0
 public static BigDouble Sqr(this BigDouble value)
 {
     return(BigDouble.Pow(value, 2));
 }
示例#26
0
 public static double Log(this BigDouble value, double @base)
 {
     return(BigDouble.Log(value, @base));
 }
示例#27
0
 /// <summary>
 /// Joke function from Cookie Clicker. It's an 'egg'.
 /// </summary>
 public static BigDouble Egg(this BigDouble value)
 {
     return(value + 9);
 }
示例#28
0
 public static double Log2(this BigDouble value)
 {
     return(BigDouble.Log2(value));
 }
示例#29
0
 public static double Ln(this BigDouble value)
 {
     return(BigDouble.Ln(value));
 }
示例#30
0
 public static BigDouble Negate(this BigDouble value)
 {
     return(BigDouble.Negate(value));
 }