Here you can find the source of bitsRequired(double minValue, double maxValue)
public static int bitsRequired(double minValue, double maxValue)
//package com.java2s; //License from project: LGPL public class Main { /**/*w w w . j a v a2 s.c om*/ * computes the required number of bits to represent an range * minValue...maxValue / 0..max(minValue,maxValue) * In case on of the minValue < 0 also the bit for the sign is included * */ public static int bitsRequired(double minValue, double maxValue) { long absmax = (long) Math.max(Math.abs(minValue), maxValue) + 1; int bits = 64 - Long.numberOfLeadingZeros(absmax); if (minValue < 0.0) bits++; return bits; } }