//TODO Switch to latest versions of .NET and implement a BigInt Version. /// <summary> /// Rounds the given value to the specified number of significant figures/digits. /// </summary> /// <param name="val"> The value to be rounded </param> /// <param name="digits"> the number of significant figures </param> /// <returns> the rounded number </returns> public static double RoundToSignificantDigits(double val, int digits) { if (val == 0) { return(0); } double scale = QMath.Pow(10, QMath.Floor(QMath.Log10(QMath.Abs(val))) + 1); return(scale * QMath.Round(val / scale, digits)); }
/// <summary> /// Gets the number of minimum bits required to represent this integer. Of course, all integers take the same space but a lower integer can be represented by /// less bits. /// </summary> /// <param name="number"> the integer </param> /// <returns> the bits required to represent said integer. if negative, will return 32 as negative values require the flag. input the absolute value /// if you wish the minimum bits if the number was not negative to be returned. </returns> public static int GetIntMinimumBits(int number) { if (number < 0) { return(32); } for (int i = 31; i >= 0; i--) { if (number % QMath.Pow(2, i) != number) { return(i + 1); //TODO Left here. } } return(1); }