If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Coming Soon, New Forum Experience:
We're excited to announce that soon we will be upgrading the AutomationDirect forums to a brand-new system!
This will allow us to modernize the forums, improve your accessibility, and help make it easier for you to participate in the discussions that matter to you!
If you have a login to our webstore you can use that email and password to log into the new forum. (You will have to create a nickname.) If you do not have a login to our webstore you will have to create a new account in the forum that can then be used on our webstore. You will NOT be able to use your current forum username and password to login to the new forum.
We know there is valuable information in the existing forum that has been contributed by many of you. All the posts and replies will still be available but in read only format. We are planning to use some of this content for our new Knowledge articles coming with the new forum.

I am looking for insights into converting Half Precision Floats (Float16) read via ModBus into Do-More, into their Real(Float32) equivalents. With the various possible values,
normal, subnormal, infinity, etc. I would be interested in seeing how others have handled it.

Looks like half precision is mostly used for graphics to save space and increase speed when dealing with bazillions of values, one wonders why one would be reading them with a PLC?
While there is an IEEE 754 half-precision binary floating-point format, there are also some others, one would want to be sure of the actual format before trying to write a converter.
If BobO hasn't heard of them then I'd guess the DoMore doesn't support them natively, but I'm sure it has the bit wise logical operators to allow one to write their own conversion.

Is it possible to instead of reading a Float16 via modbus, to convert that by doing math the other direction and turn it back into an integer or maybe two integers? Then read those and do your multiplication to turn it back into a float32 on the Do-More end

I assume you already tried reading your F16 into Do-More as an F32 already? I was thinking maybe it would work and make sense and just be padded with 0s
edit: I see that you actually cannot read a Float16 into a F32 with 0s padding since the exponent bits are different. Only BFloat16 seems capable of easy conversion into float32

It's just bit manipulation. You can mask the source bits. I have not looked at the spec, but say V42 contains the half precision value, then (V42 & 0x8000) is the sign bit. V42 & 0x7F10 are the 8 exponent bits, and V42 & 0x007F are the 7 mantissa bits.

MATH D0 "((V42 & 0x8000) << 16) | ((V42 & 0x7F10) << 16) | ((V42 & 0x007F) << 16)"
Then move D0 CAST as an R into R0
MOVE D0:R R0
R0 should contain the IEEE 32 bit float value

Since the definition of the 8 exponent bits match the 32 bit version, all the NaN and +/-INF should work, I believe.

franji1 In "normal" float16, it has 5 exponent bits though. Only Google's BFloat16 contains the same 8 exponents for backwards compatibility and easy conversion.

franji1 In "normal" float16, it has 5 exponent bits though. Only Google's BFloat16 contains the same 8 exponents for backwards compatibility and easy conversion.

There's a little more work to be done then. Not as simple as I spelled out. Sorry. :-\

## Comment