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); }
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(); }
public static int Sign(this BigDouble value) { return(BigDouble.Sign(value)); }
/// <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))); }
public static BigDouble Cbrt(this BigDouble value) { return(BigDouble.Cbrt(value)); }
public static BigDouble Factorial(this BigDouble value) { return(BigDouble.Factorial(value)); }
public static double Atanh(this BigDouble value) { return(BigDouble.Atanh(value)); }
public static BigDouble Cosh(this BigDouble value) { return(BigDouble.Cosh(value)); }
public static BigDouble Multiply(this BigDouble value, BigDouble other) { return(BigDouble.Multiply(value, other)); }
public static BigDouble Subtract(this BigDouble value, BigDouble other) { return(BigDouble.Subtract(value, other)); }
public static BigDouble Add(this BigDouble value, BigDouble other) { return(BigDouble.Add(value, other)); }
public static BigDouble Truncate(this BigDouble value) { return(BigDouble.Truncate(value)); }
public static BigDouble Ceiling(this BigDouble value) { return(BigDouble.Ceiling(value)); }
public static BigDouble Floor(this BigDouble value) { return(BigDouble.Floor(value)); }
public static BigDouble Round(this BigDouble value) { return(BigDouble.Round(value)); }
public static BigDouble Exp(this BigDouble value) { return(BigDouble.Exp(value)); }
public static BigDouble Sinh(this BigDouble value) { return(BigDouble.Sinh(value)); }
public static BigDouble Divide(this BigDouble value, BigDouble other) { return(BigDouble.Divide(value, other)); }
public static BigDouble Tanh(this BigDouble value) { return(BigDouble.Tanh(value)); }
public static BigDouble Reciprocate(this BigDouble value) { return(BigDouble.Reciprocate(value)); }
public static BigDouble Pow(this BigDouble value, double power) { return(BigDouble.Pow(value, power)); }
public static BigDouble Min(this BigDouble value, BigDouble other) { return(BigDouble.Min(value, other)); }
public static BigDouble Sqrt(this BigDouble value) { return(BigDouble.Sqrt(value)); }
public static double AbsLog10(this BigDouble value) { return(BigDouble.AbsLog10(value)); }
public static BigDouble Sqr(this BigDouble value) { return(BigDouble.Pow(value, 2)); }
public static double Log(this BigDouble value, double @base) { return(BigDouble.Log(value, @base)); }
/// <summary> /// Joke function from Cookie Clicker. It's an 'egg'. /// </summary> public static BigDouble Egg(this BigDouble value) { return(value + 9); }
public static double Log2(this BigDouble value) { return(BigDouble.Log2(value)); }
public static double Ln(this BigDouble value) { return(BigDouble.Ln(value)); }
public static BigDouble Negate(this BigDouble value) { return(BigDouble.Negate(value)); }