Ejemplo n.º 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);
            }
Ejemplo n.º 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();
        }
Ejemplo n.º 3
0
 public static int Sign(this BigDouble value)
 {
     return(BigDouble.Sign(value));
 }
Ejemplo n.º 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)));
 }
Ejemplo n.º 5
0
 public static BigDouble Cbrt(this BigDouble value)
 {
     return(BigDouble.Cbrt(value));
 }
Ejemplo n.º 6
0
 public static BigDouble Factorial(this BigDouble value)
 {
     return(BigDouble.Factorial(value));
 }
Ejemplo n.º 7
0
 public static double Atanh(this BigDouble value)
 {
     return(BigDouble.Atanh(value));
 }
Ejemplo n.º 8
0
 public static BigDouble Cosh(this BigDouble value)
 {
     return(BigDouble.Cosh(value));
 }
Ejemplo n.º 9
0
 public static BigDouble Multiply(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Multiply(value, other));
 }
Ejemplo n.º 10
0
 public static BigDouble Subtract(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Subtract(value, other));
 }
Ejemplo n.º 11
0
 public static BigDouble Add(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Add(value, other));
 }
Ejemplo n.º 12
0
 public static BigDouble Truncate(this BigDouble value)
 {
     return(BigDouble.Truncate(value));
 }
Ejemplo n.º 13
0
 public static BigDouble Ceiling(this BigDouble value)
 {
     return(BigDouble.Ceiling(value));
 }
Ejemplo n.º 14
0
 public static BigDouble Floor(this BigDouble value)
 {
     return(BigDouble.Floor(value));
 }
Ejemplo n.º 15
0
 public static BigDouble Round(this BigDouble value)
 {
     return(BigDouble.Round(value));
 }
Ejemplo n.º 16
0
 public static BigDouble Exp(this BigDouble value)
 {
     return(BigDouble.Exp(value));
 }
Ejemplo n.º 17
0
 public static BigDouble Sinh(this BigDouble value)
 {
     return(BigDouble.Sinh(value));
 }
Ejemplo n.º 18
0
 public static BigDouble Divide(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Divide(value, other));
 }
Ejemplo n.º 19
0
 public static BigDouble Tanh(this BigDouble value)
 {
     return(BigDouble.Tanh(value));
 }
Ejemplo n.º 20
0
 public static BigDouble Reciprocate(this BigDouble value)
 {
     return(BigDouble.Reciprocate(value));
 }
Ejemplo n.º 21
0
 public static BigDouble Pow(this BigDouble value, double power)
 {
     return(BigDouble.Pow(value, power));
 }
Ejemplo n.º 22
0
 public static BigDouble Min(this BigDouble value, BigDouble other)
 {
     return(BigDouble.Min(value, other));
 }
Ejemplo n.º 23
0
 public static BigDouble Sqrt(this BigDouble value)
 {
     return(BigDouble.Sqrt(value));
 }
Ejemplo n.º 24
0
 public static double AbsLog10(this BigDouble value)
 {
     return(BigDouble.AbsLog10(value));
 }
Ejemplo n.º 25
0
 public static BigDouble Sqr(this BigDouble value)
 {
     return(BigDouble.Pow(value, 2));
 }
Ejemplo n.º 26
0
 public static double Log(this BigDouble value, double @base)
 {
     return(BigDouble.Log(value, @base));
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Joke function from Cookie Clicker. It's an 'egg'.
 /// </summary>
 public static BigDouble Egg(this BigDouble value)
 {
     return(value + 9);
 }
Ejemplo n.º 28
0
 public static double Log2(this BigDouble value)
 {
     return(BigDouble.Log2(value));
 }
Ejemplo n.º 29
0
 public static double Ln(this BigDouble value)
 {
     return(BigDouble.Ln(value));
 }
Ejemplo n.º 30
0
 public static BigDouble Negate(this BigDouble value)
 {
     return(BigDouble.Negate(value));
 }