int n = 1000; int length = (int)(Math.log10(n)+1);
public static byte[] longToBytes(long number) { // TODO optimize int length = (int)(Math.log10(number)+1); byte[] res = new byte[length]; int i = length; while (number > 0) { res[--i] = (byte) (number % 10); number = number / 10; } return res; }
public static String readableFileSize(long size) { if(size <= 0) return "0"; final String[] units = new String[] { "B", "kB", "MB", "GB", "TB" }; int digitGroups = (int) (Math.log10(size)/Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups]; }
private static int numberOfDigits( long value ) { return max( 1, (int)(log10( value ) + 1) ); }
public String getReadableFileSize() { if (size <= 0) return "0"; final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" }; int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; } }
/** * rounds the given number to the next significant number * * @param number * @return */ public static float roundToNextSignificant(double number) { if (Double.isInfinite(number) || Double.isNaN(number) || number == 0.0) return 0; final float d = (float) Math.ceil((float) Math.log10(number < 0 ? -number : number)); final int pw = 1 - (int) d; final float magnitude = (float) Math.pow(10, pw); final long shifted = Math.round(number * magnitude); return shifted / magnitude; }
/** * Returns the appropriate number of decimals to be used for the provided * number. * * @param number * @return */ public static int getDecimals(float number) { float i = roundToNextSignificant(number); if (Float.isInfinite(i)) return 0; return (int) Math.ceil(-Math.log10(i)) + 2; }
@SuppressWarnings("NonReproducibleMathCall") private static int decodeNanos(int nanos) { if (nanos < 0) { // This means there is a second VInt present that specifies additional bits of the timestamp. // The reversed nanoseconds value is still encoded in this VInt. nanos = -nanos - 1; } int nanosDigits = (int) Math.floor(Math.log10(nanos)) + 1; // Reverse the nanos digits (base 10) int temp = 0; while (nanos != 0) { temp *= 10; temp += nanos % 10; nanos /= 10; } nanos = temp; if (nanosDigits < 9) { nanos *= Math.pow(10, 9 - nanosDigits); } return nanos; }
private static int numberOfDecimals(BigDecimal value) { double d = value.doubleValue(); return -(int) Math.round(Math.log10(d)); }
@Override protected ExprEval eval(double param) { return ExprEval.of(Math.log10(param)); } }
public static int getMinorVersion(String version, String prefix) { String s = version.substring(prefix.length()); int major = Integer.parseInt(s); s = s.substring((int) (Math.log10(major) + 2)); return Integer.parseInt(s); }
public static int getMinorVersion(String version, String prefix) { String s = version.substring(prefix.length()); int major = Integer.parseInt(s); s = s.substring((int) (Math.log10(major) + 2)); return Integer.parseInt(s); }
private static long maxPrecision(int numBytes) { return Math.round(Math.floor(Math.log10(Math.pow(2, 8 * numBytes - 1) - 1))); }
private String lineNumberToString(int lineNumber, @NotNull Editor editor) { final int lineCount = editor.getDocument().getLineCount(); final int digitsCount = (int)Math.ceil(Math.log10(lineCount)); return StringHelper.leftJustify("" + lineNumber, digitsCount, ' '); }
protected int pformat_len0( double scale, int lg ) { double dx = Math.log10(scale); int x = (int)dx; if( x >= 0 && PrettyPrint.pow10i(x) != scale ) throw H2O.unimpl(); int w=1/*blank/sign*/+lg/*compression limits digits*/+1/*dot*/+1/*e*/+1/*neg exp*/+2/*digits of exp*/; return w; }
public static DoubleValue log10( AnyValue in ) { if ( in instanceof NumberValue ) { return doubleValue( Math.log10( ((NumberValue) in).doubleValue() ) ); } else { throw needsNumbers( "log10()" ); } }
@Description("logarithm to base 10") @ScalarFunction @SqlType(StandardTypes.DOUBLE) public static double log10(@SqlType(StandardTypes.DOUBLE) double num) { return Math.log10(num); }
/** * Returns the logarithm of "a" with base 10. */ @Override protected DoubleWritable doEvaluate(DoubleWritable a) { if (a.get() <= 0.0) { return null; } else { result.set(Math.log10(a.get())); return result; } }
@Test public void testLog10() { for (double doubleValue : DOUBLE_VALUES) { assertFunction("log10(" + doubleValue + ")", DOUBLE, Math.log10(doubleValue)); } assertFunction("log10(NULL)", DOUBLE, null); }