Here you can find the source of toFloat(short half)
Parameter | Description |
---|---|
half | The half floating point value as a short. |
public static float toFloat(short half)
//package com.java2s; //License from project: Apache License public class Main { /**//from w ww. jav a 2 s. c om * Converts a single precision (32 bit) floating point value into half * precision (16 bit). * * <p> * Source: <a * href="http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf"> * http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf</a><br> * <strong>broken link</strong> * * @param half * The half floating point value as a short. * @return floating point value of the half. */ public static float toFloat(short half) { switch ((int) half) { case 0x0000: return 0f; case 0x8000: return -0f; case 0x7c00: return Float.POSITIVE_INFINITY; case 0xfc00: return Float.NEGATIVE_INFINITY; // TODO: Support for NaN? default: return Float.intBitsToFloat( ((half & 0x8000) << 16) | (((half & 0x7c00) + 0x1C000) << 13) | ((half & 0x03FF) << 13)); } } }