Share via


Half.ToHalf(Single) Method

Definition

Converts the specified single-precision float value into a half-precision float value.

[Android.Runtime.Register("toHalf", "(F)S", "", ApiSince=26)]
public static short ToHalf (float f);
[<Android.Runtime.Register("toHalf", "(F)S", "", ApiSince=26)>]
static member ToHalf : single -> int16

Parameters

f
Single

The single-precision float value to convert to half-precision

Returns

A half-precision float value

Attributes

Remarks

Converts the specified single-precision float value into a half-precision float value. The following special cases are handled:

<ul> <li>If the input is NaN (see Float#isNaN(float)), the returned value is #NaN</li> <li>If the input is Float#POSITIVE_INFINITY or Float#NEGATIVE_INFINITY, the returned value is respectively #POSITIVE_INFINITY or #NEGATIVE_INFINITY</li> <li>If the input is 0 (positive or negative), the returned value is #POSITIVE_ZERO or #NEGATIVE_ZERO</li> <li>If the input is a less than #MIN_VALUE, the returned value is flushed to #POSITIVE_ZERO or #NEGATIVE_ZERO</li> <li>If the input is a less than #MIN_NORMAL, the returned value is a denorm half-precision float</li> <li>Otherwise, the returned value is rounded to the nearest representable half-precision float value</li> </ul>

Java documentation for android.util.Half.toHalf(float).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to