Lesser-known .NET 5 feature: the new Half floating-point type

Posted: (EET/GMT+2)

 

The soon-here .NET version 5 (RC2 is just out) introduces a not so well known numeric type called System.Half, which provides a 16-bit floating-point value. The classic C# type float is a 32-bit value, and is called a single-precision type. This new type could be called half-precision, if you want to follow the pattern. The C# type double is of course a double-precision type with its 64 bits.

Okay, that now out of the way, the new Half struct is intended for scenarios where storage size matters more than precision. It uses half the memory of float and a quarter of double.

Half value = (Half)123.45f;

Console.WriteLine(value);
Console.WriteLine(sizeof(Half));

Internally, Half implements the IEEE 754 binary16 format. The value range is smaller than float, and precision is lower as well. The ranges are as follows:

Half.MinValue: -65500
Half.MaxValue: 65500

Typical use cases include:

  • graphics and image processing
  • machine learning workloads
  • GPU interop
  • large datasets where memory bandwidth matters.

Simple conversions work directly:

Half halfValue = (Half)10.5f;

float singleValue = (float)halfValue;
double doubleValue = (double)halfValue;

Also worth noting: C# does not introduce a new language keyword for Half, so you use the struct name directly.

For most business applications, float and double still make more sense. But if you are handling large numeric buffers, image data, or machine reading related workloads, the reduced memory footprint can be useful.