package net.sprd.bitcompact.schema;

import net.sprd.bitcompact.BitStorage;

public class FloatingBitSchema extends AbstractDoubleBitSchema{

    private double factor;
    private double minValue;
    
    public FloatingBitSchema(int bitCount, double factor, double minValue) {
        super(bitCount);
        this.factor=factor;
        this.minValue=minValue;
    }
    
    public double getDouble(byte[] data, int offset) {
        return bitCount>32 ?
                (BitStorage.getLong(data, offset, bitCount)/factor)+minValue:
                    (BitStorage.getInt(data, offset, bitCount)/factor)+minValue;
    }
    public int setDouble(byte[] data, int offset, double value) {
        if (bitCount>32) {
            BitStorage.setLong(data, offset, bitCount, (long)(((value-minValue)*factor)+0.5));
        } else {
            BitStorage.setInt(data, offset, bitCount, (int)(((value-minValue)*factor)+0.5));
        }
        return this.bitCount;
    }


}

@@ -191,24 +191,401 @@
 nValue;%0A    
+/**%0A     * store unsigned integer for (value-minValue)*factor with bitCount bits%0A     * handle values between %5BminValue ; minValue + ((2%5EbitCount -1)/factor)%5D, %0A     * precision (minimal distance between 2 values) is 1/factor %0A     * %0A     * @param bitCount number of bits to store%0A     * @param factor factor to scale number to int%0A     * @param minValue minimum value%0A     */
 %0A    public 

optimize floating