0

I'm looking for a way to optimize float32 value, that contains only values from (0, 1) for wireless transfer.

enter image description here

Since in my case all values are positive, I've already trimmed Sign bit, but now I need some help

I think, that my next step is going to be trimming all Fraction trailing zeroes zeros, and then, somehow optimize Exponent part

But I'm not quite sure, maybe there is already some bit-level optimizations exists for same cases, since using float32 to store values between (0, 1) is very common practice

Data integrity and error correction are not relevant in my case

leon0399
  • 79
  • 8
  • there was exactly a question like yours in the past but I couldn't find it now. The answer is you can, but you'll get only 1 more bit from the exponent (because half the representable values are in the range `[0, 1)` and the remaining are in `[1, ∞)`), or you'll get a larger range. For unsigned float you can use a trick like this [Storing non-negative floating point values](https://stackoverflow.com/a/64869420/995714) – phuclv Jun 21 '21 at 15:28
  • You could try to use fixed-point precision. It would be cleaner and simpler than hacking IEEE754 32-bit floats. The downside is that the precision near zero is less good while fixed-point precision benefit from a better overall precision in average. – Jérôme Richard Jun 21 '21 at 21:06

1 Answers1

0

So, I've decided to just use uint16_t, where 0=0f and 65365=1f, which is enough for me. But at memory level I'm not actually using float at all. This integer-based logic helped me not only achieve shorter byte sequence for wireless transfer, but also use less memory

Other option is to use uint32_t, that will use the same amount amount of bits

Conversion to float, if you need it, is smth like this:

float to_float = (float) value / (float) UINT16_MAX
leon0399
  • 79
  • 8