Announcement

Collapse
No announcement yet.

Float to 32bit result

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

  • Float to 32bit result

    Hello,

    I use diablo16 ulcd35DT.
    I get a float result ex : 234567 from flt_MUL instruction.
    I need to convert this float result in a unsigned 32bit number result.
    Exactly the reverse of flt_ULTOF(&Fresult,uvar32).
    Somthing as: flt_FTUL(&floatval).

    Could you help me?
    Rdgs

  • #2
    Hello,

    This forum post may help http://forum.4dsystems.com.au/forum/...d-43-diablo-16

    Best regards

    Paul

    Comment


    • #3
      Hello paulelio,

      I see the post and this is not what I need. These posts did not say how to convert a float in unsigned 32bit integer.
      I am use the LCD in designer environement and flt_FTOI(&floatval) is doing what I need except when the float is higher than 32767.
      What I need is a function with a float in and a 32 bit unsigned out
      BR
      Spo

      Comment


      • #4
        Hello Spo.

        Can you please let me know what you plan to do with the float once it has been converted to 32 bit unsigned.

        Best regards

        Paul

        Comment


        • #5
          Hello Paul,
          I program à ltc6948 rf synthesizer and one of its register has 18 bit size. This register is à décimal part of a number. This décimal part has to be multiply by 2exp18. After that this number (below 2exp18) Will be send by ulcd 35 to the ltc6948 spi port
          br
          spo

          Comment


          • #6
            Hello Spo,

            Thank you for the extra information. I hope this code will help you. I had help with this and hopefully it should be straightforward to pass the data to the ltc6948

            Code:
            func main()
                var f[2], i[2], c[6], p ;
            
                flt_VAL(f, "1234567890"); // create a large in in a float
            // flt_VAL(f, "4294500000"); // create a large in in a float
            
                flt_PRINT(f, "%10.0f\n"); // print it to verify result and demonstrate the precision loss in floats
            
                to(c) ; // 1.
                flt_PRINT(f, "%10.0f"); // 2. print the float number again to a string
                p := str_Ptr(c) ; // 3. raise a string pointer to the string
                str_GetD(&p, i); // 4. convert string to 32 bit int
            
                p := str_Ptr(i) ; // raise a string pointer to the 32 bit int
                str_Printf(&p, "%lu\n"); // and print it using the relevant function
                repeat
                forever
            
            endfunc
            Best regards

            Paul

            Comment


            • #7
              Hello Paul,

              Sorry Paul, your code does not run because its seams that you forget how a float is buiIt : four bytes in diablo16: with sign, exponent and mantis.
              So,I think you can't use str_GetD(&p,i) to convert the float format in 32bit integer.
              I tried your code and at the end of your code : str_Print(&p, "%lu\n") gives nothing.

              Rdgs

              Spo

              Comment


              • #8
                A float is definitely only 2 elements.

                That code sure works for me.

                Can you post the exact variant of that code that doesn't work?
                Mark

                Comment


                • #9
                  Hello Mark,

                  Your post "A float is definitely only 2 bytes" So +/- 32767: OK

                  I tried the exact Paul code and it gives just:
                  12345678936
                  12345678936

                  In Paul code "str_Printf(&p, "%lu\n");" do nothing because the pointed recipient is not a number in character format.

                  Paul code gives:
                  12345678936 due to " flt_PRINT(f, "%10.0f\n"); // print it to verify result and demonstrate the precision loss in floats
                  and a second time
                  12345678936 due to " flt_PRINT(f, "%10.0f"); // 2. print the float number again to a string

                  but the last code line " str_Printf(&p, "%lu\n"); // and print it using the relevant function do nothing because the diablo16 does not recognize a number in string format pointed by p pointer.

                  So, this not what I need.
                  I need a function with which convert a float to a int_32 bits large. As int_18 bis large is enough for my application I built a code which test each bit above diablo16 var

                  // calcul of NUM
                  flt_VAL(two_power_8, "262144"); // 2exp18 is neede for LTC6948 chip for 18bit large LTC6948 register
                  flt_MUL(ltc_NUM, ltc_F, two_power_18); // ltc_F is a decimal part of a number result from calculation for LTC6948 chip

                  // Managing of bit NUM[17]
                  if(flt_GE(ltc_NUM,"131072")) // Low byte=h08: put 1 NUM[17] if ltc_NUM >= 131072
                  flt_SUB(ltc_NUM,ltc_NUM,"131072"); // subtraction of 131072 from ltc_NUM
                  ltc_buffer[4] := ltc_buffer[4] | 1<<5; // put 1 in NUM[17]
                  endif

                  // Managing of bit NUM[16]
                  if(flt_GE(ltc_NUM,"65536")) // Low byte=h08: put 1 NUM[16] if ltc_NUM >= 65536
                  flt_SUB(ltc_NUM,ltc_NUM,"65536"); // subtraction of 65536 from ltc_NUM
                  ltc_buffer[4] := ltc_buffer[4] | 1<<4; // mse à 1 de NUM[16]
                  endif

                  etc....

                  At the end the result is spread in ltc_buffer[4] and ltc_buffer[5].

                  This not beautiful but if you have another idea...

                  Best Regards

                  Spo

                  Comment


                  • #10
                    Sorry about my post, I should have said "A float is definitely only 2 elements."

                    In addition a float is a single precision IEEE-754 float as defined here https://en.wikipedia.org/wiki/IEEE_754

                    You are interpreting the code wrongly
                    Code:
                    12345678936 due to " flt_PRINT(f, "%10.0f"); // 2. print the float number again to a string
                    does not print anything on the display, due to the preceding 'to()', add some more prints to the code to make it clearer.

                    Your code makes frequent errors, eg flt_GE() and flt_SUB() only accept floats, not an integer in a string.
                    Mark

                    Comment

                    Working...
                    X