Java Float to Bit floatToShortBits(float fval)

Here you can find the source of floatToShortBits(float fval)

Description

float To Short Bits

License

Open Source License

Declaration

public static short floatToShortBits(float fval) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static short floatToShortBits(float fval) {
        int fbits = Float.floatToIntBits(fval);
        int sign = fbits >>> 16 & 0x8000;
        int val = (fbits & 0x7fffffff) + 0x1000;

        if (val >= 0x47800000) {
            if ((fbits & 0x7fffffff) >= 0x47800000) {
                if (val < 0x7f800000)
                    return (short) (sign | 0x7c00);
                return (short) (sign | 0x7c00 | (fbits & 0x007fffff) >>> 13);
            }// www.  j  a  v a2 s .c  om
            return (short) (sign | 0x7bff);
        }
        if (val >= 0x38800000)
            return (short) (sign | val - 0x38000000 >>> 13);
        if (val < 0x33000000)
            return (short) (sign);
        val = (fbits & 0x7fffffff) >>> 23;
        return (short) (sign | ((fbits & 0x7fffff | 0x800000) + (0x800000 >>> val - 102) >>> 126 - val));
    }
}

Related

  1. floatToIntBits(final float f)
  2. floatToIntBits(float value)
  3. floatToIntBits(float value)