1

Possible Duplicate:
32-bit to 16-bit Floating Point Conversion

How do I convert between 32-bit floats and 16-bit half-precision floats in C?

Community
  • 1
  • 1
Anton
  • 5,932
  • 5
  • 36
  • 51

2 Answers2

1

I suggest you checking up this half_floats

You should also think about the way you will store these half-floats (there is no such type in C)

Xentatt
  • 1,264
  • 22
  • 35
1

Since C typically doesn't have a 16-bit floating point type built-in, I would expect you would either have to

  1. Use some super-specific platform "magic", like a dedicated CPU instruction if available. This will of course not be a C solution, it will likely be inline assembly in the C source. Not portable.
  2. Manually extract the required bits into perhaps an unsigned short. This will be portable, but might be a lot slower.

Both of these assume all you want to do is build the value's representation, you can't do arithmetic using C's operators of course.

unwind
  • 391,730
  • 64
  • 469
  • 606