Announcement

Collapse
No announcement yet.

Half Precision (Float16)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Half Precision (Float16)

    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.

  • #2
    Interesting. I have never heard of half precision.

    Comment


    • #3
      https://en.wikipedia.org/wiki/Half-p...g-point_format

      Comment


      • #4
        https://en.wikipedia.org/wiki/Half-p...g-point_format

        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.

        Comment


        • #5
          I wonder if the conversion makes sense if you do not have a (F16)datatype to store/transmit it.

          Comment


          • #6
            There is also this https://en.wikipedia.org/wiki/Bfloat...g-point_format
            basically, 8 exponent with an 7-bit (truncated) significand

            Comment


            • #7
              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
              Last edited by MikeN; 03-26-2020, 08:28 AM.

              Comment


              • #8
                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.
                There are 10 kinds of people in this world, those who know binary, and those who do not.

                Comment


                • #9
                  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.

                  Comment


                  • #10
                    Originally posted by BobO View Post
                    Interesting. I have never heard of half precision.
                    Almost everything I do is half precise!

                    Comment


                    • #11
                      Originally posted by MikeN View Post
                      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. :-\
                      There are 10 kinds of people in this world, those who know binary, and those who do not.

                      Comment


                      • #12
                        The offset in the exponent is different. You'll need to account for that
                        thePLCguy

                        Bernie

                        Comment


                        • #13
                          Originally posted by kewakl View Post

                          Almost everything I do is half precise!
                          If you're half precise then I must be quarter

                          Comment

                          Working...
                          X